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/ . 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'
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( + "/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.