Automator upload workflow

I often find myself want to upload one or two files from my iBook to my main machine at work. Starting my FTP/SFTP program (Yummy FTP), waiting for it to connect, then copying the files seems like too many steps for a simple operation. So I wrote an Automator workflow that does the job in a single step: I control-click the file’s icon on my iBook and select the “Upload to Work” item from the Automator submenu. Off goes the file.

Before I give the details, you should know three things:

  1. My work computer allows remote access via SSH. This includes not only the ssh program itself, but also the sftp and scp file transfer programs. To set this up, I checked the Remote Login service in the Sharing panel of System Preferences.
  2. My iBook has ssh-agent running, which, in effect, automatically provides my ssh passphrase whenever it’s requested. With this, I can use programs like ssh, sftp, and (in this workflow) scp to access my work computer without typing in my passphrase every time—I only have to type it in once after logging into the iBook. I wrote about my ssh-agent setup in this post a couple of years ago.
  3. I’ve come to prefer zsh to bash as my Unix shell. This affects one small part of the workflow.

With that in mind, here’s the workflow. You can click on the image to see it full-sized.

The first action simply gets the items selected in the Finder and passes their names along to the second action, a shell script that does the file transfer.

Note that the shell is set to /bin/zsh and the input is passed as arguments to the script. The source code of the script is:

source ~/.keychain/${HOST}-sh

for f in "$@"
do
    scp "$f" username@remote-mac:Desktop/
done

The first line “sources,” or loads, the contents of a file that sets certain SSH-related environment variables used by ssh-agent. Again, you should go to my older post to get the background information. The purpose of that line is to allow the workflow to run the later scp command without asking me to enter my SSH passphrase. If I had set the workflow’s shell to /bin/bash, this line would have been

source ~/.keychain/${HOSTNAME}-sh

because bash and zsh use different names for the environment variable that holds the hostname of the computer.

The rest of the lines just loop through the selected files and send them off to the Desktop of the remote computer via the scp (secure copy) command. Obviously, the actual workflow uses my real username and the real IP number for the work computer on either side of the “@” symbol.

Tags: