I'm looking for advice or suggestions on the best way to pass variables between Applescript and Livecode.
Let's say I have created a Service menu item in Automator (see thread: viewtopic.php?f=9&t=36167)
I can then assign a keyboard shortcut system wide. If user was (say) in a browser or mail app, they could select some text and hit the keyboard shortcut and service menu applescript will invoke.
In my example below I show how you can grab the context of the user (which app is frontmost) and what text they have selected in that app.
But how can I pass this text to Livecode? The method of using dispatch works for passing a simple string (like the active app) but is not so great for passing say a large block of text (where you really need to pass a variable).
There should be a way to dispatch an appleevent to Livecode, but I haven't seen a workable example of how to do this. I'm aware that there are some extra steps to get this working in a standalone, for now, I am first interested in getting this working in the IDE.
Code: Select all
on run {input, parameters}
-- get the frontmost app so we can interrogate if needed (e.g. browser) for user context
tell application "System Events"
set activeApp to name of first application process whose frontmost is true
end tell
-- TEST script to show input string user has selected when they invoked the service menu item. How can I pass this variable to LIvecode?
set tUserSelectedText to input as string
display dialog tUserSelectedText
tell application "LiveCode VERSION"
activate
do script "dispatch \"MYHANDLER\" to stack \"MYSTACK\" with " & quote & activeApp & quote
end tell
return input
end run