using applescript to parse parameter to Application

Hi - I’m brand new to applescript and uncertain if I can use applescript to solve following problem: :confused:
I want to open an executable file (*.osx - made with Director) & parse a parameter to this application using applescript?
Unfortunately I did’t find a solution jet - I just can run the application, but can’t parse any parameters?
My script so far:


tell application "Finder"
	activate
	select file "index.osx" of folder "test" of disk "CDR"
	open selection
end tell

If there isn’t a way - what 'd you suggest doing? I’m trying to avoid having 50 different executable starter-files - each one would be about 5 MB - Which takes too much space on a CDR… Compiled Applescripts are much smaller…
Thanks for any suggestions!
Wommi

Hi Wommi,

You can open applications/scripts and passing arguments by using the do shell script command. Here is an example that uses a bogus argument:


set filepath to "/Volumes/CDR/test/index.osx"
do shell script "open " & quoted form of filepath & " -size 500x600"

But of course, your application/scripts (index.osx) needs to support/accept passed arguments.

Thanks Martin - but unfortunately I can’t make it working - I’m not sure what I’m doing wrong because I’m brand new to this…
So I think it might help to describe what I was doing:
I was trying to run the script in the “Script Editor” using the “Run”-button - To limit the chances of errors I’ve taken out all paths:


set filepath to "/index.osx"
do shell script "open " & quoted form of filepath & " -size 500x600"

As result I’m getting a pop-up by the Script-Editor - it seems like AppleScript doesn’t allow me to add any parameters?:

I was trying another way too:


set filepath to "index.osx"
set para to " -hallo"
do shell script "open " & quoted form of filepath & quoted form of para

But the result was an error too:

this means, the file index.osx must exist on the top level of the startup disk

Yes it does - but it doesn’t matter if I’m using the full path or not - it doesn’t even start the script because of those error messages…
The code doesn’t seem to be valid?

PS: I’m using
ScriptEditor Version 2.2 (2.2)
AppleScript 2.0

Hi Wommi,

If the «open» command does not work for you, then you can also try to execute the application/script directly (make sure its permissions are set to 755):


set filepath to "/Volumes/CDR/test/index.osx"
set para to "-hallo"
do shell script quoted form of filepath & space & quoted form of para

For example, I just wrote a small Python script named test.py containing the following code:

[i]
#!/usr/bin/python

import sys
print sys.argv[1]
[/i]

The script’s permissions are set to 755 and it is located on my desktop. The following code works for me:


set filepath to POSIX path of (((path to desktop) as Unicode text) & "test.py")
set para to "Yeah"
set shellresult to do shell script quoted form of filepath & space & quoted form of para
display dialog shellresult

Hi Martin
I think we are getting there…:stuck_out_tongue: There are still some obstacles to take.
Good news:
The script gets compiled now! Don’t know why the “open” shell command doesn’t work for me…


set filepath to "/Volumes/CDR/test/index.osx"
set para to "-hallo"
do shell script quoted form of filepath & space & quoted form of para

I set the permissions to 755 in the terminal

and checked it:

So it seems it should work now… When I run the applescript-application-file it comes up with the following:
“Press Run to run this script, or Quit to quit.” - It’s like in Windows :smiley:

And when I press run it comes up with:

“sh: /index.osx: Permission denied”

Then I thought it could help to chmod the index.osx too - but it didn’t help:

“Press Run to run this script, or Quit to quit.” - Not again!

“sh: /index.osx: cannot execute binary file”

any ideas?
I’ll try this Python script later… and have a coffee now
Cheers for the help so far!

Hi Wommi,

There is no need to change the permissions of the AppleScript application itself, it’s already executable when saved with Script Editor. But of course you need to make sure that your *.osx file is executable (chmod755).

Nevertheless you will run into problems when the *.osx file is not executable at all (on Mac OS X). You can easily test this by simply dragging the *.osx file into a Terminal window, then hit Return. If it won’t run from there, it also won’t run using the «do shell script» command.

HTH :smiley:

indeed - I get using the terminal:
Permission denied
and after chmod:
cannot execute binary file

Strange thing is that I can run it using the script

tell application "Finder"
   activate
   select file "index.osx" of folder "test" of disk "CDR"
   open selection
end tell

but no parameters are allowed there… I think I’m going in circles… But I’m not giving up jet

The shellscript “open” could still be a solution - If I get it working… - Do you have any ideas why it doesn’t work?

Hi Wommi,

You might be interested in this thread:

Macromedia Director Projector on Leopard