Page 1 of 2

Return value from AppleScript

Posted: Sat Nov 23, 2019 2:40 pm
by Klaus
Hi all,

I need to knwo if my standalone is currently actvie or not.
I found this snippet on the net:

Code: Select all

tell application "System Events"
	set activeApp to name of first application process whose frontmost is true
	return activeApp
end tell
Works fine in the AppleScript Editor, but I get "execution error" when DOing this in LC!?
Any hints appreciated!


Best

Klaus

Re: Return value from AppleScript

Posted: Sat Nov 23, 2019 4:02 pm
by richmond62
That's "odd" considering AppleScript and LiveCode are NOT the same thing. 8)

For starters, I can't find tell in the LC Dictionary.

How about using send message to to the app that runs appleScripts?

I had "a bash" that didn't work:
-
Screenshot 2019-11-23 at 17.10.18.png
-
nothing appeared in the Message Box. :(

Presumably because return activeApp is not understood nor received by LiveCode.

Re: Return value from AppleScript

Posted: Sat Nov 23, 2019 4:58 pm
by richmond62
Started "fooling around" with appleScript:
-
Screenshot 2019-11-23 at 17.48.26.png
-
that made me feel a bit funny.
-
Screenshot 2019-11-23 at 17.50.25.png
-
Err . . . OK

It dumps the name of the foremost application into the Script Editor's "Message Box equivalent,"
and that's marvellous: but I don't quite see how that will arrive inside a LiveCode stack.
-
Screenshot 2019-11-23 at 17.56.37.png
-
I have a feeling I'm going in a reasonable direction, but how
I can copy the name of the activeApp to the clipboard is what interests me.

Re: Return value from AppleScript

Posted: Sat Nov 23, 2019 5:18 pm
by richmond62
This:
[Apple Script] if run in the Script Editor

Code: Select all

tell application "System Events"
	set activeApp to name of first application process whose frontmost is true
	set the clipboard to the activeApp
end tell
does put the name of the active application (Script Editor) onto the clipboard

but a paste command inside LiveCode does NOT return that,
suggesting the clipboard is not shared properly.

Re: Return value from AppleScript

Posted: Sat Nov 23, 2019 5:22 pm
by richmond62
Oh, look, what I found lurking in a dark, dark corner:
-
lrg.jpg
-
June 2001 edition

picked it up for 3 dollars (well, 5 Bulgarian leva, really) about 6 years ago and started reading it
"on the pot," lasted about 5 minutes.

Never mind, I've just been 'nasty" and rubbed my wife's face in
her tendency to urge me to chuck things like that out. 8)

Re: Return value from AppleScript

Posted: Sat Nov 23, 2019 6:10 pm
by [-hh]

Re: Return value from AppleScript

Posted: Sat Nov 23, 2019 7:10 pm
by richmond62
Yup: that works:

Code: Select all

on mouseUp
   do fld "fGoget" as "applescript"
   put the result into fld "fOUTPUT"
end mouseUp
-
Screenshot 2019-11-23 at 20.08.30.png
-
a moment to think . . .
-
Screenshot 2019-11-23 at 20.08.48.png

Re: Return value from AppleScript

Posted: Sat Nov 23, 2019 7:12 pm
by richmond62
I wonder if there is a comprehensive list of all the alternateLanguage possibilities?
-
Screenshot 2019-11-23 at 20.11.04.png

Re: Return value from AppleScript

Posted: Sat Nov 23, 2019 8:18 pm
by [-hh]
I wonder if there is a comprehensive list of all the alternateLanguage possibilities?
Well, the alternateLanguages ...

Just to note for "not yet"-MacOS 10.15 users:
The dialog above that Richmond displays in his screenshot is issued ONCE if you accept (then there isn't such a dialog any more with ANY other LC version >= 8.x).

Re: Return value from AppleScript

Posted: Sat Nov 23, 2019 9:17 pm
by richmond62
issued ONCE if you accept
Indeed.

MacOS 10.14.6

I have not upgraded to 10.15.1 yet.

Re: Return value from AppleScript

Posted: Sat Nov 23, 2019 9:18 pm
by richmond62
This:
[Apple Script] if run in the Script Editor

Code: Select all

tell application "System Events"
set activeApp to name of first application process whose frontmost is true
set the clipboard to the activeApp
end tell


does put the name of the active application (Script Editor) onto the clipboard

but a paste command inside LiveCode does NOT return that,
suggesting the clipboard is not shared properly.
I still do not understand why the clipboard contents, which would paste into TextEdit correctly,
would not paste into a LiveCode field, but the last thing I had copied in LiveCode pasted instead.

Surely LiveCode should use the system-wide clipboard rather than some eccentric arrangement of it own?

Re: Return value from AppleScript

Posted: Sat Nov 23, 2019 9:38 pm
by FourthWorld
richmond62 wrote:
Sat Nov 23, 2019 9:18 pm
I still do not understand why the clipboard contents, which would paste into TextEdit correctly,
would not paste into a LiveCode field, but the last thing I had copied in LiveCode pasted instead.

Surely LiveCode should use the system-wide clipboard rather than some eccentric arrangement of it own?
Nearly all apps use both an internal clipboard and the OS-supplied clipboard, translating between them as needed to keep them in synch. This is done because the OS clipboard must use formats common to all apps, and most apps have their own internal structures for data, often containing additional info not needed in another app.

LC's clipboard commands underwent significant change several versions ago to handle a much broader set of use-cases than was possible before.

It may be that there's something about the way AppleScript stores clipboard data that the LC IDE script isn't accounting for.

One quick test would be to use the paste command directly in the Message Box rather than rely on whatever script is in the IDE for handling that.

It may also be useful to example the keys of the clipboardData array - those keys are described here:
https://livecode.com/resources/api/#liv ... pboarddata

Re: Return value from AppleScript

Posted: Sat Nov 23, 2019 10:44 pm
by richmond62
Aha:

Code: Select all

on mouseUp
   do fld "fGoget" as "applescript"
   select after fld "fOUTPUT"
   if the clipboard is "text" then paste
end mouseUp
along with this:
-
Screenshot 2019-11-23 at 23.43.16.png
-
certainly works.

Re: Return value from AppleScript

Posted: Sun Nov 24, 2019 8:08 am
by richmond62
Screenshot 2019-11-24 at 9.05.53.png
Screenshot 2019-11-24 at 9.05.53.png (9.41 KiB) Viewed 12103 times
-
What exactly defines an 'active scripting' language?

Or, put another way:

Where can one find a reasonably comprehensive list of active scripting languages for Macintosh
and Windows?

AND . . . Wot? No Linux?

Re: Return value from AppleScript

Posted: Sun Nov 24, 2019 9:17 am
by FourthWorld
richmond62 wrote:
Sun Nov 24, 2019 8:08 am
AND . . . Wot? No Linux?
Most system integration on Linux is done with bash and Python, both of which use stdin and stdout, so they can be used from the LC's shell function.