2009-12-24

Mac OS X Services - Changes between Tiger, Leopard and Snow Leopard

When a file or folder is selected in the Finder and a Mac OS X Service is invoked, either through the Services menu or its keyboard shortcut, the input fed to the service depends on what version of Mac OS X is running.
  • In Tiger, (10.4), no input is fed to the service.
  • In Leopard (10.5), the absolute path to the file is the input. E.g. "/Users/steve/tablet.rtf"
  • In Snow Leopard (10.6), if the service is configured properly to work on files and folders, then the input will be file URL like "file://Users/steve/tablet.rtf".
In Leopard, any service that accepted selected text would automatically work with selected files or folders in the Finder. However, Snow Leopard changed that. It is still possible for a service to accept both selected text and files plus folders, but if you create a Service using Automator, you are forced to choose one or the other. So, pick one and save your Service. For this example, I'm assuming you picked 'Files and Folders'.

Next, edit the ~/Library/Services/Foo.workflow/Contents/Info.plist and change this:


<key>NSSendFileTypes</key>
<array>
<string>public.item</string>
</array>

to this:

<key>NSSendFileTypes</key>
<array>
<string>public.item</string>
</array>
<key>NSSendTypes</key>
<array>
<string>NSStringPboardType</string>
</array>


Then, in the Python program that is your service, you may want something like this to detect that your input is a file path:


if input.starswith('file://') or input.startswith('/'):
# I think I got a file path as input


For more details, see Services Properties in the Mac Dev Center. Happy holidays!