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)

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:

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.

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:

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’:

I see. Thanks, guys!

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)?

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:

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