Page 1 of 1

AS to AS comms?

PostPosted: Tue Jul 13, 2010 8:22 am
by anode
Its a little off topic, but can an applescript talk to another? Do they need to be an 'app' over a script?

Re: AS to AS comms?

PostPosted: Tue Jul 13, 2010 8:54 am
by jay (support)
Yes, you can, in much the same way that AppleScripts talk to Indigo - via apple events. You need to save your scripts as applications - at least a script that's the destination of a communication. So, a simple example:

Server Script saved as "SimpleServer.app":
Code: Select all
on showMessage(theMessage)
    display dialog theMessage
end showMessage


Client Script:
Code: Select all
tell application "SimpleServer"
    showMessage("Here's a test message")
end tell


2-way communication is much more tricky, since AppleScripts execute on the main thread. Each script would have to somehow process work but give periodic time to the main event loop to process incoming messages. I've never tried it before so I'm not sure how it would work. It might work by creating an AppleScript application in Xcode - that may give you the main event loop from which you can periodically run an AppleScript to do the processing and give you time to processes apple events from other processes. But, again, I've never tried it.

But, without more details of the problem domain it's just abstract thinking... ;)

Re: AS to AS comms?

PostPosted: Tue Jul 13, 2010 9:25 am
by anode
Thanks man!
Just need them hello world styles to point me in the right direction.