Friday, October 16, 2009

TIP:Applescript to invoke All Windows function of Exposé and bind it to key you please

Here is the applescript to invoke the All Windows function of Exposé :
on run
-- delay is needed so that keybindings defined in
-- tools like Fastscripts works
delay 0.1
tell application "System Events"
-- 101 is key code for F9 key
key code 101
end tell
end run
Assuming you have bound Exposé:All Windows function to F9 key.

So you say - what is the big deal?

Well, if you look at System Preferences... > Exposé and Spaces pane > Exposé Tab , you will see that it allows you to bind various functions to limited set of keys. The script enables you to bind it to any key such as Option+Tab. How? Heres how:

Save the above script in ~/Library/Scripts/Expose.app . Then bind it to Option+Tab using Quicksilver or Launchbar or Fastscripts.

Saturday, October 03, 2009

Un-minimize minimized windows and bring them to front using Applescript

While implementing the AWS tool that I talked about in the last post - I learned a cool new Applescript technique to unminimize minimized windows. Here it is:

-- assuming you have name of a minimized window
set theWindowName to ....

-- is it minimized?
if (value of attribute "AXMinimized" of window theWindowName is true) then
-- first un-minimize the window
value of attribute "AXMinimized" of window theWindowName to false
end if

-- raise it
perform action "AXRaise" of window theWindowName

I had not much documentation on attributes such as "AXMinimized" and perform action "AXRaise".

Friday, October 02, 2009

Ruby on Rails : Injecting routes from a separate file

I am currently working on a Ruby on Rails (RoR) application and needed a mechanism to load routes that are generated into a file by another tool. After some experimentation I came up with the following solution.

In a Ruby on Rails application the routing is configured using the config/routes.rb file. The routes are defined using the draw method of ActionController::Routing::Routes class like this:
ActionController::Routing::Routes.draw do |map|
...
map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end
The block is executed with a local variable map in the scope. I wanted to insert routes defined in a separate file that is generated by another tool. To do that I tried to use the load or require methods. However I realized that it will not work because the load or require methods reset the scope to the top level. So I came up with the following:


# insert routes from generated file
instance_eval(File.read(File.expand_path(File.dirname(__FILE__)) + "/generated-routes.rb"))


Basically it is evaluating the contents of a file in the instance (current) scope. The File.expand_path(File.dirname(__FILE__)) simply computes the path to folder that contains routes.rb file. To that I append the name of generated routes file which lives next to routes.rb file.

Is there a better/idiomtic way to do this?

AWS - a unified Application and Window Switcher i.e. a Command TAB alternative

My other pet peeve with Mac OS X is how it deals differently with Applications and Windows that are minimized or hidden when one navigates using Command TAB( TAB)/Command Shift Tab ( TAB).

When on asked about any alternatives to the IMHO broken Command Tab behavior, frequently Mac-heads respond condescendingly about:

For me it does not matter if it is a window or application...I want to be able to switch to various windows where I want to work - hidden, minimized or what ever. Using Command TAB ( TAB)/Command Shift Tab ( TAB) to switch between applications and Command ~ ( ~)/Command Shift ~ ( ~) to switch between windows of an application is just plain wrong.

Once again, I was aggravated enough to make me write a tool to address just those issue. I wrote the AWS tool.

Read more...

Tuesday, July 14, 2009

Update: Move Resize tool for Mac OS X

What's new?

Now you can directly enter location (x,y) and/or size (width,height) in the text fields and then type enter to move and/or resize the window.

Read more...

Tuesday, July 07, 2009

Origins Symposium - shear delight!

Origins Symposium

Thursday, May 28, 2009

A Swing component to display last keystroke and keystroke history

A Swing component to display last keystroke. Also shows the keystroke history.

How it works

The KeyLabel component registers a global listener for KeyEvents using:
Toolkit.getDefaultToolkit().addAWTEventListener(this, AWTEvent.KEY_EVENT_MASK);
On receiving KEY_RELEASED event formats the KeyStroke as a string and displays it. The dropdown shows history of last 100 keystrokes. Clicking on the X (Clear KeyStroke History) button clears the keystroke history. The KeyEvent listening can be suspended by deseleting the checkbox.

Usage
JComponent keyLabel = KeyLabelFactory.createKeyLabel();
// Use keyLabel in your application's statusbar
Demo

Download (KeyLabel.jar)
> java -jar KeyLabel.jar
Screenshot of KeyLabel Demo



Source Code

Wednesday, May 27, 2009

Error launching Mozilla (only from inside Eclipse) using simple Runtime.exec() on Ubuntu.

I discovered that, on Ubuntu 9.04, I cannot launch mozilla browser using the simple invocation of Runtime.getRuntime().exec("/usr/bin/mozilla"). It turns out, I have to use the variant of exec() where I can pass in some environment variables explicitly.

Here is the program that I used to test it:
import java.io.IOException;

public class MB {

/**
* @param args
*/
public static void main(String[] args) {
try {
Process exec = Runtime.getRuntime().exec("/usr/bin/mozilla"
// Uncommenting out following line will launch mozilla browser on Ubuntu
//, new String[] {"DISPLAY=:0.0", "HOME="+System.getProperty("user.home")}
);
System.out.println(exec.waitFor());
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
}

}
Very interesting. May be that is why Eclipse has trouble launching help in default external browser on Ubuntu.

UPDATE: It turns out that this fails only if I run the above program from inside Eclipse. If I run it from a terminal window it works. It turns out that Eclipse sets an environment variable MOZILLA_FIVE_HOME to point to /usr/lib[64]/xulrunner-addon to make the SWT's embedded browser widget work correctly. However this environment variable is inherited by any process that is launched from within Eclipse. And apparently MOZILLA_FIVE_HOME inteferes with the Mozilla browser (/usr/bin/mozilla) launch.

Two issues have been filed in Eclipse Bugzilla:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=278415
https://bugs.eclipse.org/bugs/show_bug.cgi?id=278296