After a lot of messing around, I've managed to get this working under OSX...
This is how I'm doing it:
in the AppleScript Script Editor, write the following script:
on open location this_URL
do shell script "/jobs/tech/scripts/shotgunLocalCommand.py '" & this_URL & "'"
end open location
If you want to make sure you're running the Python from a certain shell (in my case, I'm using tcsh generally, and have a .tcshrc file that defines some environment variables that I want to have access to) then that middle line might want to be:
do shell script "tcsh -c \"/jobs/tech/scripts/shotgunLocalCommand.py '" & this_URL & "'\""
I was wanting to do all of my actual processing inside a python script - but because of the way URL handers work in OSX, they have to call an application bundle rather than a script, so doing this in AppleScript seemed to be the easiest way to do it.
in the Script Editor, Save As an "Application Bundle"
Find the saved Application Bundle, and Open Contents. Find the Info.plist file, and open it. Add the following:
<key>CFBundleIdentifier</key>
<string>com.mycompany.AppleScript.Shotgun</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>Shotgun</string>
<key>CFBundleURLSchemes</key>
<array>
<string>shotgun</string>
</array>
</dict>
</array>
Just before the last two lines, which should be:
</dict>
</plist>
There are three strings in there that might want to be changed:
com.mycompany.AppleScript.Shotgun
Shotgun
shotgun
The third of these is the handler ID - so a URL would be shotgun://something
So, then this passes over to the Python script.
This is what I've got for this:
#!/usr/bin/env python
import sys
import urllib
arg = sys.argv[1]
handler, fullPath = arg.split(":", 1)
path, fullArgs = fullPath.split("?", 1)
action = path.strip("/")
args = fullArgs.split("&")
params = {}
for arg in args:
key, value = map(urllib.unquote, arg.split("=", 1))
params[key] = value
So if you've told your ActionMenuItem that the URL you want it to use is:
shotgun://playQuicktime
You'll end up with, in that Python script, the variable 'action' containing "playQuicktime" (or "playquicktime" - I have a feeling it lowercases everything) and params will be a dictionary containing all of the variables that are passed through from Shotgun (as listed in then "POST contents" section here: https://support.shotgunsoftware.com/entries/110709-creating-custom-menu-items-for-integration-with-other-pipeline-tools