MacOS - sending AppleEvents (AppleScript.OSAScript)
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
MacOS - sending AppleEvents (AppleScript.OSAScript)
How can I send some AppleScript from newLISP?
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
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
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
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!
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!
You can use the {,} braces in newLISP to make it easier with the quotes mess:
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
Code: Select all
(! {osascript -e 'tell app "Finder" to display dialog "hello world"'})
; or
(process {osascript -e 'tell app "Finder" to display dialog "hello world"'})
Instead of the {,} delimiters you could also use the [text], [/text] tags; this allows you to embed bigger multiline portions of osascript.
Lutz
Here is a simple way to get output back from osascript:
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
Code: Select all
> (exec {osascript -e 'tell app "Finder" to display dialog "hello world"'})
("button returned:OK")
>
Lutz
-
- Posts: 2038
- Joined: Tue Nov 29, 2005 8:28 pm
- Location: latiitude 50N longitude 3W
- Contact:
That's very nice - no quoting problems and AppleScript responses too!Lutz wrote:Here is a simple way to get output back from osascript:LutzCode: Select all
> (exec {osascript -e 'tell app "Finder" to display dialog "hello world"'}) ("button returned:OK") >
Thanks. This is looking pretty good!