Resizing Applications with Alfred and Ruby

Introduction

When on the move with my laptop, I end up having to resize all my applications which is time consuming to say the least. The main difference is due to two very difference screen resolutions:

  • Home Screen = 2560×1440 pixels
  • Laptop Screen = 1440×990 pixels

The worst is when moving from my smaller laptop resolution back to the big screen at home because all my applications are severely squished. I finally got fed up with the manual labor of resizing my desktop environment each time and crafted a solution: Alfred + Ruby. Win!

Requirements

This post assumes you are familiar with the following:

You might also want to read my previous post, Connecting Alfred to Bitly via Ruby, to understand my reasoning for using a bash shell wrapper script when using multiple Ruby installs.

Setup

You’ll want to download the following scripts:

  • rvm_ruby - A Bash shell script for dealing with multiple Ruby installs.
  • app_resizer.rb - A Ruby script for resizing applications.

…and install them as follows (for example):

  • /bin/rvm_ruby
  • ~/path/to/your/ruby/scripts/folder/app_resizer.rb

Feel free to configure the app_resizer.rb script to your liking. The applications and related bounds are specific to my environment but you’ll find that it is easy enough to add your apps and bounds to your liking. The script only supports two modes: home and laptop. Again, feel free to tweak as you desire.

To configure Alfred, open preferences and go to your terminal command settings (click to enlarge):

Alfred Terminal Commands

…and here are my settings for the app resizer script and command in Alfred (click to enlarge):

Alfred - App Resizer

Usage

Once the Ruby script and Alfred settings are configured, I can now perform the following keyboard commands to resize all running applications:

  • OPTION + SPACE
  • resize home + ENTER

…or…

  • OPTION + SPACE
  • resize laptop + ENTER

I wrote the Ruby script so that it only affects running applications. If you later launch an application after you have resized your applications, you can always run the Alfred “resize” command again. Easy peasy.

Resources

You have probably noticed by now that I’m using rb-appscript gem in my Ruby script. I did this because I really don’t enjoy writing pure AppleScript code. Should you decide to get more involved with AppleScript, I highly recommend downloading the associated rb-appscript tools: ASDictionary and ASTranslate.

Enjoy.

Wednesday, June 1st, 2011 Software

No comments yet.

Leave a comment

You must be logged in to post a comment.