Return value from AppleScript

Deploying to Mac OS? Ask Mac OS specific questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Klaus
Posts: 13806
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Return value from AppleScript

Post by Klaus » Sat Nov 23, 2019 2:40 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Return value from AppleScript

Post by richmond62 » Sat Nov 23, 2019 4:02 pm

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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Return value from AppleScript

Post by richmond62 » Sat Nov 23, 2019 4:58 pm

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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Return value from AppleScript

Post by richmond62 » Sat Nov 23, 2019 5:18 pm

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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Return value from AppleScript

Post by richmond62 » Sat Nov 23, 2019 5:22 pm

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)

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Return value from AppleScript

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

shiftLock happens

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Return value from AppleScript

Post by richmond62 » Sat Nov 23, 2019 7:10 pm

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

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Return value from AppleScript

Post by richmond62 » Sat Nov 23, 2019 7:12 pm

I wonder if there is a comprehensive list of all the alternateLanguage possibilities?
-
Screenshot 2019-11-23 at 20.11.04.png

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm
Location: Göttingen, DE

Re: Return value from AppleScript

Post by [-hh] » Sat Nov 23, 2019 8:18 pm

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).
shiftLock happens

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Return value from AppleScript

Post by richmond62 » Sat Nov 23, 2019 9:17 pm

issued ONCE if you accept
Indeed.

MacOS 10.14.6

I have not upgraded to 10.15.1 yet.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Return value from AppleScript

Post by richmond62 » Sat Nov 23, 2019 9:18 pm

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?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Return value from AppleScript

Post by FourthWorld » Sat Nov 23, 2019 9:38 pm

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Return value from AppleScript

Post by richmond62 » Sat Nov 23, 2019 10:44 pm

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.

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 9287
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Return value from AppleScript

Post by richmond62 » Sun Nov 24, 2019 8:08 am

Screenshot 2019-11-24 at 9.05.53.png
Screenshot 2019-11-24 at 9.05.53.png (9.41 KiB) Viewed 9619 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?

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 9802
Joined: Sat Apr 08, 2006 7:05 am
Location: Los Angeles
Contact:

Re: Return value from AppleScript

Post by FourthWorld » Sun Nov 24, 2019 9:17 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Post Reply

Return to “Mac OS”