Tuesday, July 26, 2011

Mac: Keyboard shortcut to launch program in current space

Have you ever wanted to open an internet browser or a terminal to do a small task only to find that OS X sends you to an already open program on a different space.  This was really annoying me so I spent some time figuring out a solution that works great for me.

We'll start with opening a terminal window because it is easier.
  1. Launch AppleScript Editor
  2. Copy and paste the following code into the editor

    tell application "Terminal"
    do script ""
    activate
    end tell


  3. Save the file as ~/Library/Scripts/Open-Terminal.scpt
  4. Open Finder and go to the ~/Library/Scripts folder
  5. Open Quicksilver (if you do not have it install it from here)
  6. Click the small down arrow and click on Triggers
  7. Click the "+" sign to add a new HotKey
  8. Drag Open-Firefox.scpt from the Finder window into the window that opens
  9. Click on the Trigger column to change the Hot Key (shortcut key)
  10. Now when you press the Hot Key a new Terminal window should appear on whatever space you are currently on and open redirect.html which instantly loads www.google.com
For Firefox
  1. Launch AppleScript Editor
  2. Copy and paste the following code into the editor

    tell application "Firefox"
        open "~/Library/Scripts/redirect.html"
        activate
    end tell


    this code tells Firefox to open and go to redirect.html
  3. Save the file as ~/Library/Scripts/Open-Firefox.scpt
  4. Open Finder and go to the ~/Library/Scripts folder
  5. Create ~/Library/Scripts/redirect.html in a text editor and paste the following code into the file

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title>Redirecting</title>
    <meta http-equiv="REFRESH" content="0;url=http://www.google.com"></HEAD>
    <BODY>
    <p> Redirecting </p>
    </BODY>
    </HTML>
  6. Open Quicksilver (if you do not have it install it from here)
  7. Click the small down arrow and click on Triggers
  8. Click the "+" sign to add a new HotKey
  9. Drag Open-Terminal.scpt from the Finder window into the window that opens
  10. Click on the Trigger column to change the Hot Key (shortcut key)
  11. Now when you press the Hot Key a new Firefox window should appear on whatever space you are currently on

1 comment: