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!

5 comments:

Darrell Golliher said...

Curious about what service you wrote. Anything you can tell us about?

-D

John Speno said...

Hi Darrell,

It started with a service to open specific requests in HelpSpot if a request ID number was selected. From there the service has grown over time to cover other uses. For example, searching HelpSpot based on a name or email address, looking up USPS tracking numbers etc). One keyboard shortcut and a few simple heuristics based on the input are so useful that I can't imagine life w/o them now.

Anonymous said...
This comment has been removed by a blog administrator.
Unknown said...
This comment has been removed by a blog administrator.
Obat Pembesar Penis said...
This comment has been removed by a blog administrator.