Transferring variables between AppleScript and LiveCode

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sipsuper
Posts: 1
Joined: Wed Jun 10, 2026 7:54 am
Contact:

Transferring variables between AppleScript and LiveCode

Post by sipsuper »

Hello, everyone.

may anyone explain how I may pass a variable from Applescript to Livecode? The execution context is Applescript (e., I am not running Applescript from within Livecode).

The example I'm attempting to get working is providing a value from a service menu applescript.

I believe this could be accomplished by sending an Appleevent and then interrogating the value of the Applescript (event handler) in Livecode, but I haven't found an example.

Thank you in advance for your ideas.
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Transferring variables between AppleScript and LiveCode

Post by bn »

hi sipsuper,

Long ago I did some inter application communication using AppleScript. LC's AppleScript support is limited. Digging in my old AS scripts I adapted one to what I think is similar to what you have in mind.
The AppleScript script: (use apple script's ScriptEditor to trigger the AS script from outside of LC)

Code: Select all

set tParameter to the current date
set tParameter to "  your value  " & the seconds of tParameter --  a test parameter/ would be your parameter
set tStackName to "ReceiverStack" -- your stackname here
set tCommand to "foo" -- your receiver handler here at the card level or up

-- construct an AppleScript script for Livecode here
set myScript to "send \"" & tCommand & "\" && quote & \"" & tParameter & "\" & quote to current card of stack \"" & tStackName & "\""
tell application "LiveCode 10.0.4" to do script myScript -- this executes the 
set x to the result
Create a stack "Receiver" with 1 field "fRes" with a script at the card level:

Code: Select all

on foo pParameter
   beep
   put pParameter into field "fRes"
end foo
Kind regards
Bernd
Last edited by bn on Thu Jun 11, 2026 11:15 am, edited 1 time in total.
stam
Posts: 3210
Joined: Sun Jun 04, 2006 9:39 pm

Re: Transferring variables between AppleScript and LiveCode

Post by stam »

Hi Bernd,

I'm not sure that's the what the OP is asking but may be wrong.
Looks like they're using AppleScript independent of LiveCode but want to send an AppleScript event to LiveCode with a value to be processed there.

This strikes me as the wrong way round and my understanding is about the same as yours. But I'm not sure how an AppleScript can pass an event to LiveCode when the script is not running within LiveCode, which is my understanding of the OP (happy to be corrected...)
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Transferring variables between AppleScript and LiveCode

Post by bn »

Hi Stam,

I am not sure what the OP has in mind either.
I figured the OP has a Livecode thing running that uses the parameter from "service menu applescript" outside of LC to process it in a Livecode stack.
That is what the example shows. The AScript would be integrated in the external process.
I am quite curious to know his use case is.
Kind reagards
Bernd
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: Transferring variables between AppleScript and LiveCode

Post by dunbarx »

Bernd, Stam.

Is it possible the OP is talking about the form "do as AppleScript", and wants some data to return to LC?

Craig
bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4219
Joined: Sun Jan 07, 2007 9:12 pm

Re: Transferring variables between AppleScript and LiveCode

Post by bn »

Is it possible the OP is talking about the form "do as AppleScript", and wants some data to return to LC?
I think right now it is best to let the original poster explain in more detail what he wants.

KInd regards
Bernd
stam
Posts: 3210
Joined: Sun Jun 04, 2006 9:39 pm

Re: Transferring variables between AppleScript and LiveCode

Post by stam »

dunbarx wrote: Thu Jun 11, 2026 3:23 pm Is it possible the OP is talking about the form "do as AppleScript", and wants some data to return to LC?

Always possible, and as Bernd says, best to wait for the OP to clarify, but according to the initial post (emphasis mine):
The execution context is Applescript (e., I am not running Applescript from within Livecode).
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: Transferring variables between AppleScript and LiveCode

Post by dunbarx »

Stam.

Right you are.

But assuming LC is running on his machine, and whatever the source of the appleScript, how would any such source pop itself into LC? Where would it land?

Craig
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10416
Joined: Fri Feb 19, 2010 10:17 am

Re: Transferring variables between AppleScript and LiveCode

Post by richmond62 »

That might be a 'clever' bot: considering it is a single post
Post Reply