I'm trying to write a simple AppleScript application that handles sftp:// and sshfs:// URLs on my Mac. Based on a good guide on how to create a custom URL handler app in AppleScript, I wrote a small app as follows and it works well when I click on a URL with the corresponding schemes. Actual work is done in a separate shell script that calls sshfs(FUSE), and I'm using AppleScript just to interface it with the OS.
on open location theURL
set cmd to (quoted form of (get POSIX path of (path to resource "sshfs.sh" in directory "Scripts"))) & " " & theUrl
do shell script cmd
end open location
However, this custom URL handler AppleScript app doesn't work if I use the open
command from Terminal, e.g.,
open sftp://host/path
I tried adding other handlers and found the command-line way invokes on run argv
handler instead of the one I've written, but can't figure out how to access the passed URL argument. I can access the URL correctly when the script is invoked directly, e.g., osascript my.applescript sftp://host/path
. Tried ASObjC Runner, but did not help.
Is there a standard handler or a method in an AppleScript application for receiving the arguments passed over the open
Unix command? It seems it relies on AppleEvents, but I can't find a good reference describing how to play the same magic between the command and native apps using AppleScript.