Monday, May 29, 2017

#1 2016-11-10 08:44:26 pm

Schmye Bubbula
Member
Registered: 2003-11-22
Posts: 105

Confusion with "name of me"

In Snow Leopard, "name of me" is the name of the app it's running in, whether it's an AppleScript applet, or run from AppleScript Editor. But in El Capitan, "name of me" when run within Script Editor is the name of the script or document window, such as, "Untitled." What's up with that? I can understand new language features that break scripts across versions of macOS, but why purposely cause scripts to break by apparently assigning an entirely different meaning or referent to a given syntax?

AppleScript: 2.1.2
Browser: Firefox 45.0.2
Operating System: Mac OS X (10.6.8)

Offline

 

#2 2016-11-11 04:20:00 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2621

Re: Confusion with "name of me"

Now every script object has the property name and anonymous objects has the name missing value. While in Mac OS 10.6 an script objects doesn't have the property name when not explicitly defined. On older systems when you get the name of an anonymous script object it will follow the parenting chain until it finds a name, most likely the name of the top level object constant AppleScript like in your 'name of me' example.

In El Capitan every object has name property but the top level script object has the name of the document. So to get the same results as on Snow Leopard, meaning you actually want the name of the AppleScript constant, you simply can use the code on older and newer systems like this:

Applescript:

name of (get properties of AppleScript)

Because that is actually the code you want, you never wanted the name of me but its parent. However I agree that when an "bug" is this long in AppleScript Apple should know that users would rely on this and they should have left it in there.

Last edited by DJ Bazzie Wazzie (2016-11-11 04:35:57 am)

Offline

 

#3 2016-11-11 04:52:32 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 4286

Re: Confusion with "name of me"

"Schmye Bubbula wrote:

… but why purposely cause scripts to break by apparently assigning an entirely different meaning or referent to a given syntax?

Hi.

It's more that the implentation's been refined in an attempt to match what is meant by 'me'. According to the AppleScript Language Guide:

AppleScript defines the keyword me to refer to the current script and the keyword it to refer to the current target. (The current script is the one that is currently being executed; the current target is the object that is the current default target for commands.) It also defines my as a synonym for of me and its as a synonym for of it.

Note that 'me' refers to the script itself. It's also broadly interpreted as meaning the file or document containing it. The application running the script is (and has aways been) the 'current application':

The current application constant refers to the application that is executing the current AppleScript script (for example, Script Editor).


NG

Offline

 

#4 2016-11-11 05:42:48 am

Schmye Bubbula
Member
Registered: 2003-11-22
Posts: 105

Re: Confusion with "name of me"

I see. Thanks, guys!

Offline

 

#5 2017-03-19 10:05:20 am

Schmye Bubbula
Member
Registered: 2003-11-22
Posts: 105

Re: Confusion with "name of me"

I'm still a little confused, after all. Somebody please tell me what "name of me" returns under post-Snow Leopard within:

1) an AppleScript applet named "Test Applet"
2) an AppleScript applet named "Test Applet" that spawns an osascript in turn executing the "name of me"

In #2, it would return, "osascript" if I instead used "name of current application as string," so should I still use "name of me" if I want the name of the spawning applet (or is it hopelessly impossible in post-Snow Leopard)?

Offline

 

#6 2017-03-20 08:10:09 am

Nigel Garvey
Moderator
From: Warwickshire, England
Registered: 2002-11-19
Posts: 4286

Re: Confusion with "name of me"

Hi.

1) "Test Applet"
2) "missing value"

osascript is an executable program in its own right, invoked by a shell script. The script code it executes is either passed to it as text or is indicated by a path to a script file.

So, as you say, 'name of current application' returns 'osascript' in situations where osascript is executing the code. In the same situations, 'name of me' returns 'missing value' if the code is just passed text, or it returns the name of the indicated script file (without the extension) if that's where the code resides. Your applet and osascript are separate applications and there no connection between the applet's AppleScript environment and that in which the passed code is (compiled and) executed.

If the osascript code needs to know the name of the applet, that has to be written into it by the applet:

Applescript:

do shell script "osascript -e 'set appletName to \"" & name of current application & "\"'"

Last edited by Nigel Garvey (2017-03-20 08:11:29 am)


NG

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.050 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)