Launch AppleScript app from shell script and pass filename parameter?

I’ve written two AppleScript application bundles that use different methods for converting a file (or files) that the user can drop onto the application – or, if the user double-clicks the application, the user can select a file from a choose file dialog.

For various reasons, I would now like to combine these two applications into one, and I think it may be easiest if I simply store one bundle inside the other. This means that, in cases where I want the second (embedded) bundle to process the file, I would run a shell script that launches the second (embedded) bundle with the filename of the file as a parameter, something like this:

do shell script “osacript /path/to/the/embedded/ /path/to/the/filename/to/be/converted”

But when I experiment with this command in the terminal, I get an error message saying that no user interaction is allowed.

I’ve searched the forum for a way around this, and haven’t found one, but maybe I haven’t looked hard enough. Is this simply impossible?

Thanks for any help.

An application is a bundle. Inside the bundle is the actual script, so you have to use that command with the script instead of the application bundle. osascript is for running applescripts not applications.

A second way to do this is to use an applescript command instead of a shell command. If you turn the application into a script, then you can use the applescript command "run script scriptPath with parameters {“some parameter”}


I guess the last posts of this discussion might be of some interest for you.

Best regards from Snow Slush City,


Thank you for both replies. I will test whether I can change the application into a script bundle and will hope that works.

Well if you’re getting this error in the terminal there isn’t much wrong with your script only with your parenting. The run handler has a parent and when your script has a display dialog (not inside a tell application block) the display dialog will be send to the current application, in this case osascript. Normally when working in script editor your current application is script editor who will show the dialog for you. So when you want to show the user a dialog form osascript you should use:

telll application "Finder" to display dialog "hello world!"

To come back to your answer you if it is impossible or not, yes it’s possible. There are two ways to do this.

Make another script and make a run handler like this

on run argv --argv: list of strings like unix arguments passed
if count argv = 0 then
--there are no arguments
else if count argv = 2 then
--well we've got the number of arguments we want in this example
set arg1 to item 1 of argv
set arg2 to item 2 of argv
tell application "Finder" to display dialog ("Argument 1: " & arg1 & return & "Argument 2: " & arg2 as string)
end if
end run

on the commandline you would simply do this “osascript -s s /path/to/script.scpt argument1 ‘argument 2’”

To answer my own question, it turned out to be much easier than I thought.

I wanted one AppleScript to launch another AppleScript app contained inside it, and send a filename to the second AppleScript as a parameter.

The various solutions offered here didn’t work in this situation, even when I specified the “main.scpt” inside the AppleScript application. What did work was this:

set myScriptApp to quoted form of "/path/to/my/embedded/AppleScript"

set myFile to quoted form of "/path/to/the/file/that/should/be/processed/by/myScriptApp"

do shell script "open -a " & myScriptApp & space & myFile

I hope someone finds this useful.

First of all I don’t know why it shouldn’t work. I use that method all the time for backgrounding and passing arguments. And second of all your method must say that it will only work with passing file names (because open checks for it existence) and your script must be an application.

I must say my example works best for passing any kind of parameters (only string values) and as much as you want. Also osascript will run any kind of script.

Well I’m glad you found a good solution yourself and it is nice looking code.

p.s. I post this also for other readers who will come shortly (I refer to this post in an other post to complete his answer ).