Calling an applescript with a string as a parameter

Hello,

Hopefully I am not missing something obvious, but I am trying to do something that I feel should be easy. Basically, I have a closed application that I can’t modify. It has the ability to call an external application with a string (it could be a URL, etc.). I would like to have it call an applescript application and use the string as a parameter to the script.

I tried this:


on run argv
	display dialog argv
end run

Which works great if I call it from a command prompt using osascript, but if I make is an app and try to run it directly from the closed application, I get the error:

“<> doesn’t understand the <> message.”

I have tried using “item 1 of argv”, too, and get the message “Can’t get item 1”. Since it seems that may be more dialog related an error, if I leave out the dialog I get “<> doesn’t understand the open message.”.

Any suggestion or pointers would be greatly appreciated. I found several resources on calling applescripts with parameters, but nothing that seemed to be exactly what I am trying to do.

I am trying this on 10.4.1 w/Applescript 1.10 (I think).

Thanks,
Todd

One method, though not pretty, is to use osascript. Its a method of calling applescripts from the terminal. Standard usage is “osascript {path to script} {inputs}”, which is then accessed exactly how your test script is done. I’m not sure if your application would be able to run it that way, but its at least a start.

You don’t say how your ‘closed application’ calls the external app. Knowing what event it sends is rather important.


That suggests it’s sending the extenal an ‘open’ event, in which case you need to provide an ‘open’ handler. Your current ‘run’ handler is most likely a red-herring: the applet shell will automatically call it whenever the applet is launched. (Also, the ‘display dialog’ command in your ‘run’ handler will error unless the handler is called with a direct parameter, which most callers, including the applet shell, won’t do. This probably explains why you had [unrelated?] troubles there.)

Try changing your ‘run’ handler into an ‘open’ handler and see if that does the trick. Also, find out exactly what parameters it can pass to that handler, since you’ll want to make sure you handle them correctly. And see if there’s any other events you might need to handle as well. e.g. Sensible apps typically send URL strings via an ‘open location’ rather than ‘open’ event, which is meant to be used for passing a list of file reference objects.

HTH

Thanks for the information.

osascript works for passing the parameter, but there is an issue running it due to the way the process invokes osascript. It is running as a different user and since upgrading to 10.4 that does not seem to be allowed any more.

I tried using open as the action previously, but nothing seems to happen. The script loads and ends without even displaying the dialog box. I also tried open location. I will look into how the script is being invoked.

I appreciate it.

Todd