Tuesday, May 1, 2012

Use automator to create X11 shortcuts in OSX

I have a Mac and yet I do a fair amount of work in X11apps on Linux systems.  I really like the ssh's -Y flag that let's me run my Linux X11 apps and have their display output (and input) sent back to my Mac.


I just stumbled onto this in Automator and thought it might be worth sharing.

You can create Automator "Application" workflows that look/feel/behave like local OSX applications, but are actually running on remote Linux servers.  In this posting, I will walk through creating an Automator workflow for Synaptic, an application package manager for apt based Linux distributions.

Requirements

You will need to ensure you have an environment that meets the following requirements in order to follow along:

  • A Mac running OSX (I'm using Lion.  I've not tested this with other versions so if you're using another version, your milage may vary.)
  • You will need X11.app or XQuartz.app installed on your Mac.  X11.app comes with OSX up to Lion.  After Lion, you will need to install XQuartz.app yourself.
  • Access to a Linux system that is running SSH with X11 tunneling enabled (a default I believe) and gksudo and synaptic installed.
  • You need to have key-based authentication set up with your account so you are not prompted for a password when logging into the Linux machine via ssh.
gksudo is normally not needed.  In this case we're running synaptic, a package manager for Linux, which needs elevated privileges in order to add/remove software packages on the Linux machine.  If the X11 app you are wanting to run doesn't require elevated privileges you won't need gksudo.

Verify that you can log in without as password prompt

Before we create the Automator workflow, let's verify that you can log into the Linux system from your Mac without a password prompt. Start a terminal window and issue a command in the following format:

ssh username@linux_hostname

If you are prompted for a password you will still need to set yourself up for key-based authentication.  Check out any of these links and then come back.  You should be let in without a password as seen below:


Start a new Automator Workflow

Once you have confirmed that you can ssh from your Mac into your Linux system, you're ready to get started.  Run Automator and start a new "Application' workflow.
Then we're going to add a single action to the workflow.  In the Actions library locate the Utilities group and select it.  Then drag the Run Shell Script action to your workflow.
Once you've done that, click on the Options link at the bottom of the action.  It will reveal some options.  Check the Ignore this action's input checkbox.
Finally, replace the cat command with the following ssh command:

ssh -Y username@linux_hostname gksudo -g synaptic &



Where username is your username and linux_hostname is your Linux host's hostname.  Don't forget the & at the end.  Then save your workflow as Synaptic.  You can click the run button if you'd like to test it out.
Once you're satisfied with it, quit out of automator.  Now you can run the workflow directly from OSX.  Locate it in Finder and double-click on it.

 



That's it.  You can create any number of workflows for individual Linux apps.  I have one for LibreOffice, one for synaptic, one for Eclipse and one for gnome-system-monitor.

Optional - Set icon for your workflow

If you're like me, the generic Automator icon on my Synaptic workflow is a little annoying.  You can set the icon to whatever you'd like.  Here's one way to do it.

First, obtain a copy of the synaptic.png file from your Linux machine and place it on your Mac.  I use the following command from a terminal:

scp steve@ubuntu32.local:/usr/share/pixmaps/synaptic.png ~/Desktop

This puts the synaptic.png file on my Mac's desktop.  Then I double-click the synaptic.png file.  It should open up in Preview.  In preview, I select Edit->Select All, then Edit->Copy.
Next, I control-click on the Synaptic automator workflow and select Get Info.  This brings up an informational dialog.
In the top-lefthand corner of the dialog, there is a small Automator icon.  I click on it, causing it to glow blue-ish.  While it's glowing, I press Command-V
 Finally I close the dialog.  I also delete the synaptic.png file as I no longer need it.  Now  My synaptic Automator workflow has he official synaptic icon.



I hope you found this posting helpful.