4

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.

netj
  • 111
  • 4
  • 4

1 Answers1

0

Why not just handle it in your "on run handler"? Something like this...

on run argv
    set theArg to item 1 of argv
    if theArg starts with "sftp://" then
        open location theArg
    else
        -- do the normal applescript code
    end if
end run

Or are you saying the "open" unix command doesn't pass the argument?

regulus6633
  • 18,848
  • 5
  • 41
  • 49
  • Thanks for the answer, but this was exactly what I tried. The `argv` for the run handler is set to `current application` somehow when I use the "open" unix command, so the `item 1 of argv` gives an error. It is a list of strings though, when I invoke directly with osascript. Weird, isn't it? – netj Dec 16 '12 at 21:13