Tuesday, April 3, 2012

An Alfred extension to run Linux apps in OSX

I run a Linux Virtual on my Mac via Parallels Desktop.  In a prior post, I showed how to run X11 apps on the Linux virtual, but directing the output to OSX via the ssh's X11 tunneling.  Keep in mind, the post isn't Parallels specific.  Parallels is just what I use for running virtuals.


In this post, I'll show how to create an Alfred extension to run Linux X11 apps directly from an Alfred prompt.

Things you'll need:

  • You will need to have gone through my prior post and ensure you have ssh X11 tunneling working correctly.
  • You will need to have key based authentication working with your Linux guest so that you are NOT prompted for any password when ssh'ing into it.
  • You will need to have Alfred installed (with the Powerpack).

Now let's get started.

First, pull up your Alfred preferences and go to the Extensions tab.  Click the "+" in the bottom left-hand corner and select "Shell Script".  Fill out the resulting sheet naming the extension whatever you'd like and click "Create".

This will bring you into the extension editor.  You want to keep the Keyword checkbox checked.  In the textbox next to that, enter a keyword.  I use 'lr' for 'Linux Run'.  Also, keep the Silent checkbox checked and the Action checkbox unchecked.

In the command text area, enter the following:
ssh -Y -C linux "{query}"
Be sure to replace "linux" with whatever you've named your Linux guest in the Mac's /etc/hosts file.  Also, if you're logging into the Linux guest with a user that is different than your OSX username you will want to change the ssh command format to:
ssh -Y -C johndoe@linux "{query}"
The -Y turns on ssh X11 tunneling.  The -C turns on compression.  It's not needed, but might speed things up depending on what apps you're running.  The "{query}" tells Alfred to send whatever you enter after the "lr" to ssh for processing on the Linux virtual.  Here's what mine looks like:

Be sure to click the "Save" button then close the window.

Now you're ready to give it a try.  Bring up the Alfred prompt (alt/option->space) and type "lr xlogo" and press enter/return.  You should get the XWindow logo app up on your screen.  You will need to be sure that your Linux guest is up and running when you do this.

If nothing comes up, go back into the extension editor and uncheck the Silent checkbox.  (Be sure to save).  Then try it again.  This time it will bring up a terminal window and enter your ssh command in it.  You'll be able to see any error message that results.  This should work with any X11 app that is in the Linux path.  I use it to bring up Eclipse quickly when I need to run Eclipse from Linux and not on my Mac;
lr eclipse

Also, sadly, for whatever reason, Firefox runs faster on my Linux virtual than it does natively in OSX.  So sometimes, I run firefox this way as well:
lr firefox