How is Applescript persistently resolving application name from a reference?

I am an aero engineer who does a lot of coding around physics-based simulations, but at a admittedly very primitive level (think Fortran, although we are now out of the Stone Age and writing in Python and Julia); mostly out of necessity since our programs need to be specific enough that farming out the work really does not work at all. So Applescript is simple and great for me, although I am a newbie at it.

I was messing around with trying to write some Applescripts and wanted to create a shorter reference to an application. So I started with the following just to trigger the “Where is [name]?” dialog box to appear and test if it could be done.

tell application "syn-test" to activate

So obviously, with that name not existing, Script Editor shows me a dialog box to select an application, and thereafter the reference is transformed by Script Editor to the actual name of the application the instant I hit run. Now, based on things I’ve read, I thought that this reference isn’t stored anywhere but only persists within the compiled script and disappears after I’ve deleted it. Well, I did delete that test script and found that somehow, this reference is still resolving to the application I referenced it to on every subsequent script I then use it on.

I suppose I could just leave it, but it’s maddening that I don’t understand how this works. I also don’t like unnecessary references sticking around, so I’m trying to figure out if there is a way to unassign this reference? How is it even persisting? Clearly, this reference is being stored somewhere permanently, but I have no clue or in what form.

I had a really hard time finding any documentation about this feature, but was able to find this Apple documentation from OS 9 days:
References to Local Applications

I also found this snippet from an O’Reilly guide:
External Referents Needed at Compile Time

Unfortunately, none of these tell me anything about how these references are stored or how I might manipulate them.

You mention creating a shorter reference - how would this be used, and how are you storing it? It might be helpful to include a code snippet showing what you are doing.

Well, at this point it’s really nothing involving a program that I’m working on. And the reason for it is kind of embarrassingly rudimentary for me to be calling it programming at this point. I have some disabilities that make it impossible for me to use a keyboard, so I’m relegated to using an on-screen keyboard that I point and click on with an extremely sensitive trackpad.

A lot of times, I’m writing short throwaway scripts on the terminal that simply automate certain keystroke combinations (similar to what I might use AutoHotKey on Windows). In other cases, I can invoke these as shortcuts via voice. If I’m trying to activate or target a certain application, any amount of typing that can be reduced is significant for me, so a lot of times I want to refer to a program with only a few characters. So, it probably doesn’t provide much context, but here’s an example of a simple one-liner that I might type on the terminal:

osascript -e 'tell application "mnl" to activate' -e 'tell application "System Events" to keystroke "m" using {control down, option down, shift down}'

This might be for any random thing for any program that I need to do multiple times. I haven’t really started looking into any more sophisticated automations since I’ve really just started looking at this, which put me into a rabbit hole. I just don’t like when I don’t know absolutely everything that is going on when it comes to things like environmental variables or references.

I’m not storing anything, at least not that I know of. In order to reproduce the behavior, I launch Script Editor, create a new Applescript and just type in some sort of short acronym that I want to stand in for a program whenever it’s being used in a tell block, like in the snippet below:

tell application "mnl" to activate
tell application "System Events" to keystroke "q" using {control down, option down, shift down}

if I tried this on the terminal, it would just fail with:

34:42: execution error: Can’t get application "mnl". (-1728)

But if I do it in Script Editor, instead of returning an error message, it will present a dialog box with a list of Applications asking the user to select which one you are referring to. I might browse for the application if I don’t see it in the list and select one. After that, I just delete the script from Script Editor without saving it because it has somehow permanently embedded into the environment and works from the terminal thereafter as well. I can reboot or do pretty much anything and it persists. I’m not creating any kind of alias file or anything whatsoever; the entire thing is uncomfortably opaque to me.

Try clearing your caches and see if it still holds.

Hi.

Try quitting and reopening Script Editor.

That’s a good one. It looks to be something related to the system component, as it seems to be shared across Script Editor, Script Debugger, and osascript. It is in the user settings somewhere, but doesn’t appear to be in the Script Editor or Script Debugger caches, and survives restarting the applications and a reboot.