Status
ooh, tantalizing - USGS figures the where2.0 community is ready for the hard stuff? #unfilteredpaleo
Location
Vidisha, India
Subscribe to GeoRSS Subscribe to KML


Applescript

RubyCocoa

Published in Apple, Applescript, Mac OS X, Programming, Ruby


RubyCocoa is a bridge between the Mac OS X Cocoa Framework API that makes it callable from Ruby code. You can create applications, objects, call Mac OS X Services. You can even call Applescript:


require 'osx/cocoa'
include OSX
def speak (str)
  str.gsub! (/"/, '\"')
  src = %(say "#{str}")
  NSAppleScript.alloc.initWithSource(src).executeAndReturnError(nil)
end
speak "Hello World!"
speak "Kon nich Wah. Ogan key desu ka?"

Ben Bleything submitted a talk to RubyConf, titled “Harmonize: Exploiting RubyCocoa and Sync Services for Fun and Profit” where he discusses making a wrapper around the SyncAPI in Ruby. (blog post introducing Harmonize)

RubyCocoa looks like it may have stagnated a little as the last release was November 2005, but perhaps with such a renewed interest in Ruby, and Mac OS X gaining popularity, perhaps new life with be breathed into it. Projects such as SyncBridge and Harmonize also obviously help.

Update: Check out the very good examples and information at RubyCocoa.com, including how to use your Apple Remote from RubyCocoa .


Set Latitude & Longitude of photos in iView Media Pro

Published in Apple, Applescript, Open-Source, Photography, Programming


I’m making the transition to a much more stable, usable, and tool-rich photo management tool, iView Media Pro 3. I got tired of dealing with the incredibly slow interface to iPhoto thanks to Apple’s incapable handling & testing of EXIF metadata in storing to their library.

But I digress.

Behold, there was scripting

… and it was good.

I had written an Applescript to set the latitude & longitude (and other location info) to selected photos in iPhoto. iPhoto was often beligerent and required a restart of the iPhoto (and possible database recreation) to read the location information (which was viewable in the “info” panel).

iView puts the location info as a user-editable set of fields in the EXIF data fields. Users can set city, region, country, etc. But for whatever reason, they are unable to change the latitude & longitude.

I paired down my iPhoto script to just handle latitude & longitude and handle getting the file name from iView. The tough part was how to get from the iView example selected_images to a useful POSIX path to feed to exiftool. This code does the trick.


set selectedID to selected_images(1)
if selectedID = {} then
	display dialog "No photos selected"
	return
end if

repeat with this_photo in selectedID
	set photo_path to path of this_photo
	set the image_file to the POSIX path of photo_path

Installing & Using the script

iView Location Plugin - User EntryDownload the script here and expand it in your ~/Library/Application Support/iView/Plug-ins/Scripts folder and then reload iView. You will also need exiftool, as it is the real magic behind the smoke & mirrors.

To use the script, select whatever photos you want to apply the same location information to. Then go to the “Scripts” icon in the menu bar, and choose the “Set Lat/Lon” script. Enter the latitude, longitude, and altitude in decimal format, pressing “OK” after each field. Wait a little while, and then a dialog will tell you how many photos were processed.

iView Location Plugin - Post ExportBack in iView, you should see the latitude & longitude information in the right side-bar. You can also turn on lat/lon view in the thumbnail view by pressing Command-J and selecting “Latitude” “Longitude” “Altitude”. You may need to press Command-B to rebuild the thumbnail to have the info show up the first time (or on updates).

When exporting images (say to flickr!), your geo-annotated data will stay intact and can then be mapped (or mapped).


Code paradigm converters

Published in Applescript, Programming, Python


Sometimes people put together some useful, if perhaps odd, guides.

Applescript for Python Programmers is a set of tables mapping Python syntax, functions, and interfaces to the equivalent Applescript. Actually pretty nice for understanding both languages.

Are there others out there like this? Particularly I would think the following would be particularly useful:

  • C++ < -> Obj-C
  • Javascript < -> PHP < -> Perl
  • HTML < -> XML/XSLT

Writing iPhoto Exif Data

Published in Applescript, Photography, Programming


Here is some quick Applescript that uses ExifTool to write Copyright, Title, Comments, and Keyword exif data to selected photos in iPhoto:

This script is released under the Creative Commons.


-- This applescript will set the exif keywords, name,
--  and comments of all selected iPhoto images using
--  the information current in iPhoto.
--
-- Author: Andrew Turner (http://highearthorbit.com)
--
property copyright : ¬
		"Copyright Andrew Turner, 2005. All Rights Reserved."
property URL : "http://highearthorbit.com"
property exifToolOriginal : "_original"

-- True retains copyright, False means Public Domain
property Copyrighted : "True"

tell application "iPhoto"
	activate
	try
		copy (my selected_images()) to these_images
		if these_images is false or (the count of these_images) ¬
			is 0 then ¬
			error "Please select a single image."

		repeat with i from 1 to the count of these_images
			set the keywordslist to ""
			set this_photo to item i of these_images
			tell this_photo
				set the image_file to the image path
				set the image_title to the title
				set the image_filename to the image filename
				set the image_comment to the comment
				set the assigned_keywords to the name of keywords
			end tell
			repeat with j from 1 to the count of assigned_keywords
				set the keywordslist to keywordslist & " -keywords+=" ¬
					& item j of assigned_keywords
			end repeat
			set output to do shell script ¬
				"exiftool -title='" & image_title & ¬
				"' " & keywordslist & ¬
				" " & " -comment='" & image_comment & ¬
				"' " & " -Copyright='" & copyright & ¬
				"' " & " -CopyrightNotice='" & copyright & ¬
				"' " & " -Rights='" & copyright & ¬
				"' " & " -Marked='" & Copyrighted & ¬
				"' " & "'" & image_file & "'"
			do shell script "rm '" & image_file & "'" ¬
				& exifToolOriginal
		end repeat

		display dialog "Exif writing complete."
	on error error_message number error_number
		if the error_number is not -128 then
			display dialog error_message buttons {"Cancel"} ¬
				default button 1
		end if
	end try
end tell

on selected_images()
	tell application "iPhoto"
		try
			-- get selection
			set these_items to the selection
			-- check for single album selected
			if the class of item 1 of these_items is album then error
			-- return the list of selected photos
			return these_items
		on error
			return false
		end try
	end tell
end selected_images

You can grab this script and a simpler Copyright only, as well as a Location (latitude/longitude/city,region,country) script here.