A set of scripts to create email links to movies

May 28, '05 09:26:00AM

Contributed by: mzs

Last week I showed my wonderful wife how to use Image Capture to copy movies from our camera onto the eMac. The next day she tried to email six movies of the kids to grandpa totaling around 80 MBs ... three times ... it did not work. So I thought I would help her out and wrote a droplet that lets her 'email' the movie clips. That is, it uploads the movies to a web server, then emails the links to the movies instead of the movies themselves.

Copy and paste this AppleScript into Script Editor and save as an Application. I named it 'Mail Link' and saved it into the /Applications folder. Then copy and paste this shell script into a text editor. Change the server=example.com and user=foo lines to match your server account settings. Save it as maillink into /usr/local/bin, and make it executable. Note that you cannot change this name or location without modifying the AppleScript -- the end of this hint also contains a link to an archive of everything you need, with instructions on how to install.

What this script does is it takes the file(s) you wish to email as command line arguments. It then guesses what the file types are and opens Mail.app with a new message containing link(s) to the soon-to-be-uploaded files. Then it uses scp to copy them to a web server. (You need to have an account somewhere.) You could change the last command to cp if you run a web server on your machine, and disable the BatchMode if you do not share keys with your web server. If you would like to share keys so that you do not need to enter passwords, read this article at O'Reilly about how to do it. If you want password-protected keys, look in to ssh-agent and one of either SSH Agent or SSHKeychain. Just as a meta hint, if you need to use ftp to transfer files to your webserver, curl is your friend. That way, you will not need to hard-code a password into your script. Just use the -u and -T options in the curl -- see the man curl page for more info.

This script surprised me because I actually end-up using it myself -- I just type a maillink command from the Terminal whenever I want to send something from my iBook now. For my wife, I dragged the Mail Link AppleScript application to her dock, right next to the Image Capture icon. Now she just drags the movie clips she likes from the Finder onto the Mail Link icon in the dock, composes the mail message, and sends it.

The AppleScript fires-off the maillink shell script inside of Terminal.app instead of with a do shell call, because that way you can watch the progress of your upload and whether the upload succeded or not after you compose your message. It was an old hint I used from this very site that showed me how to make a droplet :). I looked at the 'Crazy Message Text' AppleScript from Mail.app to see how to create a new message.

Here is a 4KB arhive that contains the the scripts, and a script that you can run to install it on your machine. I would have used a Makefile and install, but I think that they come with the Developer Tools. Extract the archive by double-clicking on it if you need to, open the maillink folder that was created in the Finder, and double-click on the maillink.txt file it contains. This will open it in TextEdit, so that you can change the two lines for your server and username, and save the changes. Finally open a Terminal window, cd into the maillink folder, and type this command:

sudo /bin/sh ./install.sh
That should install the AppleScript and shell script in the right places. You will have to drag the Mail Link droplet to your dock, Desktop, or wherever you want it after that.

This droplet has another useful purpose for my wife. Sometimes her father wants to print some picture of a grandchild. He wants a high-res version for that, which would be multi-megabytes in size. My wife can just drag the picture from the index view of iPhoto onto the droplet for that. She discovered this usefulness all by herself, I am so proud of her cleverness. So I added recognition for audio and image files to the shell script. It is only a matter of time until she will want to send some cute thing the kids say in an email message!

Comments (3)


Mac OS X Hints
http://hints.macworld.com/article.php?story=20050517134648758