NOTE: I’ve released an updated version of this script that uses AppleScript only.
Here’s a hack I threw together to allow me to post images from iPhoto into my Drupal image gallery. It’s a two-step process: first, there’s an AppleScript that grabs the photo information from iPhoto and puts it into a temporary file; this script then calls a PHP script that takes this information and uses cURL to do an automated login to my Drupal site and uploads the photo.
There are probably much more elegant ways of doing this, but this one has the advantage of being relatively simply and easy to modify.
Here’s what you’ll need to make this all work:
- The iPhotoToDrupal AppleScript. Save this, and then copy the text into Script Editor; set the photo_temp and php_script variables to appropriate locations on your local system, and then save the AppleScript in the Library:Scripts:iPhoto Scripts folder under home directory. Note the need for the TEC OSAX; grab and install this if you don’t have it already.
- The upload_photo_to_drupal.php PHP script. Save and uncompress this file, then move it to the location you specified with the php_script variable in the AppleScript. You should make the script executable with chmod +x upload_photo_to_drupal.php. Now edit the script and insert the proper values for your installation, including your website URL, your Drupal username and password, the location of the temporary file created (same as the photo_temp in the AppleScript) and a cookie file for cURL.
- If you don’t have the Script Menu utility installed on your Mac, go and grab it; it lets you call the AppleScript from a pop-down menu in the menubar.
Once you’ve got all of the above downloaded, installed, and configured, uploading a photo from iPhoto to Drupal is as simple as selecting a photo, and then selecting the iPhotoToDrupal script from the Script Menu:
Note that you’ll need to have at least an image “title” defined in iPhoto, as this is a required field in Drupal; an image description is optional.
Assuming everything is configured properly, you should find the selected photo uploaded to your Drupal image gallery a few seconds later.
I welcome comments on the code and the approach.