3

I have an Applescript Droplet application that I need to run from terminal. I can use osascript or even just open to open the AS App, but that will run its on run handler, not the on open droplet handler I need to be run. I tried passing the "dropped" file in (osascript /Path/To/App.app /Path/To/Droppings.txt), but it still runs the on run handler. Is there a way to do this? And if not with bash, is it possible from another AppleScript? Thanks.

  • What are you trying to accomplish with the Droplet? What is the workflow? – adayzdone Aug 29 '13 at 18:36
  • I'm not using Automator, there is no Workflow. I have two AS droplet apps. I tried using the first to call the second (I'm storing aliases of each other in the app bundles), but AS acts up since the app is within itself, so I've resorted to using bash. The idea is, if the droppings have characteristic x, pass them on to the other app's alias. Does this make sense? – scohe001 Aug 29 '13 at 18:41
  • @adayzdone huh, I didn't even know that existed. It's actually from a question on Stack Overflow that go me curious (stackoverflow.com/questions/18517313/…) – scohe001 Aug 29 '13 at 20:49
1

You can use another AppleScript that tells Finder to open files with the droplet application.

For example save this script as /Applications/droplet.app in AppleScript Editor:

on open a
    repeat with f in a
        say POSIX path of f
    end repeat
end open

Then run:

osascript -e 'on run {f}' -e 'tell app "Finder" to open POSIX file f as alias using POSIX file "/Applications/droplet.app"' -e end /bin/test

To open multiple files, convert the list of arguments to a list of file objects:

osascript -e 'on run a
set l to {}
repeat with f in a
set l to l & POSIX file f
end
tell app "Finder" to open l using (POSIX file "/Applications/droplet.app")
end' ~/*

Alternatively, create the droplet application with Automator instead of AppleScript Editor:

Then run open -a droplet2 /bin/test.

The run handler is also used for files dropped on the application. A handler named open does not have any special meaning.

One drawback of using Automator applications is that there is a relatively long delay before they are run.

  • Ahh of course. I spent the whole time trying to pass the file as a parameter while opening the application when all I had to do was open the file with the application. Silly on my part. Thanks for the help! – scohe001 Sep 1 '13 at 0:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .