MacOS - sending AppleEvents (AppleScript.OSAScript)

Started by cormullion, November 30, 2005, 01:39:32 AM

Previous topic - Next topic

cormullion

How can I send some AppleScript from newLISP?

Lutz

#1
I am not familiar with AppleScript, but if there is any possibility to initiate it from the  Mac OSX command shell (terminal window)  then you could look into the newLISP functions '!', 'process' and 'exec'.



If AppleScript is an application, which can be started from a terminal window and accepts input from standard (STDIN), then you could look into the function 'process' with the option to open I/O pipes. This would be the thightest coupling of AppleScript and newLISP. newLISP would tan be able to feed AppleScript commands directly into it and accept output from AppleScript as well.



I switched to Mac OSX in July of this year and I am interested in doing the same thing myself, using AppleScript from newLISP, but haven't had the time to pick up a book about AppleScript, perhaps both of us together can solve this problem ;). "How would I start a script written in AppleScript from a terminal window?" would be my first question.



Lutz



ps: welcome to the newLISP discussion forum

cormullion

#2
I've used the 'osascript' command to run AppleScripts before (eg from Ruby or Perl), but was wondering whether there was any more basic communication (eg an OSA interface that generates raw Apple Events).



I'll try (process) now:

--

#!/usr/bin/newlisp

(process "osascript -e 'tell app "Finder" to display dialog "hello world"'")

--



oh cool, it works! As ever, managing the quotes is the hard part... :-)



I've only just discovered newLISP so haven't even started the manual. :-) So much to learn... :-) The only two languages I know are Lisp (from the 1980s when I used Ultrix and Sun workstations) and AppleScript (from the 1990s when I went Mac) so combining the two is the next step.



I'm glad to have discovered newLisp - I haven't been enjoying my encounters with Common Lisp installations this week. newLISP looks like a great idea!

Lutz

#3
You can use the {,} braces in newLISP to make it easier with the quotes mess:



(! {osascript -e 'tell app "Finder" to display dialog "hello world"'})

; or

(process {osascript -e 'tell app "Finder" to display dialog "hello world"'})



The difference between 'process' and '!' is, that '!' blocks until osascript is completed, while 'process' will return right away.



Instead of the {,} delimiters you could also use the [text], [/text] tags; this allows you to embed bigger multiline portions of osascript.



Lutz

Lutz

#4
Here is a simple way to get output back from osascript:

> (exec {osascript -e 'tell app "Finder" to display dialog "hello world"'})
("button returned:OK")
>


There should be a way to do OSA stuff directly the way Perl/Python/TclTk do it, using 'import' in newLISP and writing an interface module, but I haven't found out yet which library etc.



Lutz

cormullion

#5
Quote from: "Lutz"Here is a simple way to get output back from osascript:

> (exec {osascript -e 'tell app "Finder" to display dialog "hello world"'})
("button returned:OK")
>


Lutz


That's very nice - no quoting problems and AppleScript responses too!



Thanks. This is looking pretty good!