How do you execute an AppleScript from within LiveCode

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
revRider
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 49
Joined: Sat Apr 02, 2011 4:06 pm

How do you execute an AppleScript from within LiveCode

Post by revRider » Fri Feb 24, 2012 2:15 pm

.. 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"


Klaus
Posts: 14194
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: How do you execute an AppleScript from within LiveCode

Post by Klaus » Fri Feb 24, 2012 2:25 pm

Hi David,

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

Best

Klaus

revRider
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 49
Joined: Sat Apr 02, 2011 4:06 pm

Re: How do you execute an AppleScript from within LiveCode

Post by revRider » Fri Feb 24, 2012 2:32 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How do you execute an AppleScript from within LiveCode

Post by Mark » Fri Feb 24, 2012 2:54 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

revRider
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 49
Joined: Sat Apr 02, 2011 4:06 pm

Re: How do you execute an AppleScript from within LiveCode

Post by revRider » Fri Feb 24, 2012 2:57 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How do you execute an AppleScript from within LiveCode

Post by Mark » Fri Feb 24, 2012 3:05 pm

David,

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

Kind regards,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

revRider
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 49
Joined: Sat Apr 02, 2011 4:06 pm

Re: How do you execute an AppleScript from within LiveCode

Post by revRider » Fri Feb 24, 2012 3:19 pm

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

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Re: How do you execute an AppleScript from within LiveCode

Post by Mark » Fri Feb 24, 2012 3:32 pm

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
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

revRider
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 49
Joined: Sat Apr 02, 2011 4:06 pm

Re: How do you execute an AppleScript from within LiveCode

Post by revRider » Tue Mar 06, 2012 2:24 pm

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

Post Reply