It doesn't work like that, because OS X doesn't treat files, folders, and URLs, which are just command line arguments to the associated programs on other systems, like other platforms. Automator programs really only can handle files and folders.
You need to create an AppleScript based application, which responds to open location
.
Open AppleScript Editor, and paste the following code (changing the script of course):
on open location myURL
do shell script "echo " & myURL & " > /Users/danielbeck/test"
end open location
Save as application. Then select the application bundle you just created, right-click, Show Package Contents, and edit Contents/Info.plist
using a text editor (after converting to XML using plutil
on the command line, if it's binary), or the default editor which is part of Apple's Developer Tools.
Add the following to its top-level structure (the screenshot is how it looks like in current Xcode, the XML is what you'd add in a text editor):
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>openme</string>
</array>
<key>CFBundleURLName</key>
<string>AppleScript Testing URL</string>
</dict>
</array>
That will associate openme://
URLs with that application. Save, move the program to a different folder and back to update Launch Services, and test it by typing an openme://
URL into a web browser's address bar:
You'll want to replace openme
by git
and the echo
call by your shell script, of course.
Best Answer
Select to create a Service in Automator that receives selected files and folders as input in Finder only. Add the Run Shell Script action and pass input as arguments.
The arguments you receive are the full Unix paths of the selected files and folders. Using
growlnotify
, part of Growl for demonstration purposes:Growl message as a result of running it on a file:
The command appears in the context menu of a file or folder in Finder. If there are too many applicable Services, they are grouped into a submenu Services.
If your script requires both the full file path, and the file name, you can do something like the following, first extracting the file name from the full path:
You can see that the file name is used as title, while the path is used as message in Growl:
If you need to query for additional input, you can execute a short AppleScript to do that. The following is a complete shell script (like the
growlnotify
above) that queries for input, and renames the selected file to that new name. I did not include error handling and such, e.g. adding colons and slashes to the new file name will likely break the script.Screenshot of a sample rename action announced via
growlnotify
: