multiple lined applescript using osascript

I have tried many different ways from implementing the following applescript as a shell command using -e and it seems never to work. I think the problem is due to the use of "run script" to create an applescript record on the fly. I want to be able to do something like:

osascript -e 'set rec to run script $argv' -e 'tell application "myapp" to etData rec'

where $arg is the parameter passed from the shell script. Any and all help is appreciated.

Tom

Original applescript below...

calling seq: test.app '{name:"query"}'

test.app:
on run argv
tell application "myapp"
try
set rec to run script (item 1 of argv)
set x to GetData rec
on error number errNum
return errNum
end try
end tell
return x
end run

G4, G5 and Intel, Mac OS X (10.5.1), Same problem on Tiger as well

Posted on Feb 10, 2008 11:34 AM

Reply
6 replies

Feb 10, 2008 12:29 PM in response to Tom Shaw

Any arguments passed to the run handler follow the script:

osascript -e 'on run argv' -e 'return "hello, " & item 1 of argv & "."' -e 'end run' 'test'

- otherwise you can just expand the text in the shell script. From your example though, there isn't a script object to run with the 'run script' statement.

You can create script objects from within AppleScript in a similar way, but I am not understanding what you are trying to do, or if a shell script is the way to do it.

Feb 10, 2008 3:58 PM in response to red_menace

Maybe I am confused but when I reduce the applescript to a shell command the real time conversion of the record "passed" from outside does not remain in existence from on -e command to another -e command

I can clearly create an applescript app and call it but I have users on Panther and it does not support applescript arguments. If I could do variable replacement at the shell level then I could support all users.

Tom

Feb 10, 2008 5:07 PM in response to Tom Shaw

As far as I can tell, you are running a script named test.app (I am guessing that it is a file somewhere), and although I don't know what it does or what values it returns, you are trying to set x to GetData rec, whatever GetData is. The run script command takes a with parameters option, so your shell script should be able to just expand that. I still do not know what you are trying to do, or why you are using the shell (you can run scripts from AppleScript as well), but that is as far as I can go without more information.

Feb 12, 2008 4:37 AM in response to Tom Shaw

Hello

I, too, am not sure what you're after by such a complicated device.
Anyway, I think one problem lies in how you quote the argument. Parameter expansion won't take place in single-quoted string.

Try something like this:

argv='{name:\"someone\"}'
osascript -e "set x to run script \"$argv\"" -e 'return name of x'



Or:

argv='{name:\"someone\"}'
osascript <<-EOT
set x to run script "$argv"
return name of x
EOT



(They are NOT tested. Also please copy code from this web page, not from subscribed email text, for I escaped some characters for posting.)

cf.
http://developer.apple.com/documentation/Darwin/Reference/ManPages/man1/bash.1.h tml
QUOTING
EXPANSION
REDIRECTION
Here Documents

Regards,
H

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

multiple lined applescript using osascript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.