Page 1 of 1

How do you execute an AppleScript from within LiveCode

Posted: Fri Feb 24, 2012 2:15 pm
by revRider
.. At a dead end here, no idea where to go.

Wrote a live code program to gather information from a user, when then is supposed to pass data to an applescript.

Running the script on its own, returns the correct results (the computer binds to AD).

Spent at least a day getting the bugs out of the applescript without redoing in Shell. Tried to convert to a bundle, application and even back to shell script. All either don't work or would take days to do the translation. Running the script and I could be done in 5 minutes.

Anyway to just run and Applescript and pass parameters?

Thanks
~David

Code: Select all

put  quote & thePath & "/BindingScript.scpt" && "'" &EmployeeNumber& "'" && "'" &EmployeePassword& "'" && "'" &MailCode& "'" && "'" &ComputerName& "'" & quote & " with administrator privileges " into tScript
      put tScript into fld "thePath" on card "MacBinding"
      do tScript as "applescript"


Re: How do you execute an AppleScript from within LiveCode

Posted: Fri Feb 24, 2012 2:25 pm
by Klaus
Hi David,

omitting the quotes should do the trick:
...
do tScript as Applescript
## you might wat to check "the result" here...
...

Best

Klaus

Re: How do you execute an AppleScript from within LiveCode

Posted: Fri Feb 24, 2012 2:32 pm
by revRider
Thanks for the quick reply...

Boss wondering when this project will be done!

Which quotes do I remove, can you link me to a correctly formatted example? Passing parameters to applescript, haven't found LiveCode examples.

Thanks, again
~David

Re: How do you execute an AppleScript from within LiveCode

Posted: Fri Feb 24, 2012 2:54 pm
by Mark
Hi David,

You can't "do" an AppleScript file. You can only "do" an actual script, for example

Code: Select all

put "run script POSIX file" && quote & theUnixPath & quote into myScript
do script myScript
It might be easier to run a script from the shell. This is an example with one parameter, containing a comma-separated list:

Code: Select all

get shell("osascript" && quote & theUnixPath & quote && theParam1 & comma & theParam2)
(I believe your parameters can't contain commas if you're using a comma separated list).

Kind regards,

Mark

Re: How do you execute an AppleScript from within LiveCode

Posted: Fri Feb 24, 2012 2:57 pm
by revRider

Code: Select all

put empty into fld "thePath" on card "MacBinding"
      put EmployeeNumber &&  EmployeePassword && MailCode && OULevel && DCSelect && ComputerName into tScriptCommand
      put thePath & "/BindingScript.scpt " &  tScriptCommand into tscript
      put tScript into fld "thePath" on card "MacBinding"
      do tScript as "applescript"
      put the result into myresults
      put ">" & myresults & "<" after fld "thePath"  on card "MacBinding"
the result is a 'compiler error'... This is new, works fine when run on its own..
Parameters not being past correctly?
(watch me bang my head on keyboard)
~David

Re: How do you execute an AppleScript from within LiveCode

Posted: Fri Feb 24, 2012 3:05 pm
by Mark
David,

You get a compiler error because you can't "do" files.

Kind regards,

Mark

Re: How do you execute an AppleScript from within LiveCode

Posted: Fri Feb 24, 2012 3:19 pm
by revRider
Ok.. makes sense, don't use Do to execute an Applescript.

Code: Select all

 put EmployeeNumber & comma &  EmployeePassword & comma & MailCode & comma & OULevel & comma & DCSelect & comma && ComputerName&&return into tScriptCommand
      get shell("osascript" && quote & theUnixPath & quote && tScriptCommand)
Results being displayed for theUnixPath & tScriptCommand.
/Users/admin/Desktop/Binding Project/BindingScript.scpt 16567,wiseguy,0224,Elementary,DC, 0224-MyBookPro

Still no joy.. Know it is hitting the code, nothing happens! Can I get results from shell? (my built in LiveCode Dictionary isn't working <sigh>)

~David

Re: How do you execute an AppleScript from within LiveCode

Posted: Fri Feb 24, 2012 3:32 pm
by Mark
Hi David,

What did you use to read the parameters in AppleScript?

Here's a real working example, which I use with HyperStudio.

If you wanted to run this script from LiveCode, you'd need the following syntax:

Code: Select all

put shell("osascript" && quote & "/Users/USERNAME/Desktop/Set Window Boundary with Params.scpt" & quote && "100,100,400,350")
If your AppleScript contains a return command, then the data should be returned by the shell function.

Kind regards,

Mark

Re: How do you execute an AppleScript from within LiveCode

Posted: Tue Mar 06, 2012 2:24 pm
by revRider
Thanks Mark your post got me on the correct path.

Here is what worked:

Code: Select all

      put thePath & "/BindingScript.scpt"  into theUnixPath 
      put  EmployeeNumber &&  EmployeePassword && MailCode && OULevel && DCSelect && ComputerName  into tScriptCommand
      put shell ("osascript"&& quote & theUnixPath & quote && tScriptCommand)
      put the result into myresults
      put theUnixPath && tScriptCommand into tscript
And thanks to everyone for getting me on the correct path!
~David