Script Editor automatically un-correcting App Name

Hello, new here, hope I’ve selected the right forum!

I’m a relative novice with Applescript. I’m writing a script that starts the application BlueGriffon, like so

tell application "BlueGriffon" to activate

It works fine, until I save & reopen the script, or Save As application. At that point, Script Editor “helpfully” updates the application to Firefox, changing the line in the script to

tell application "Firefox" to activate

I would like to know why, so that I can stop it.

I have discovered that the BlueGriffon and Firefox applications have the same Creator Code (‘MOZB’). Could this be the origin of the behavior? If so, I wonder if I can fix the problem by editing BlueGriffon’s Info.plist.

Notes:
Recommendations on alternate ways to open the application, which might proof the script against this problem, are also welcome. But it would be most satisfying to determine to problem source, compared to finding a work-around.

For those who care: The Applescript is a wrapper to handle the fact that although BlueGriffon is “maintained” for macOS, it crashes horribly when Accessibility features hit it. I suspect this level of support may be why the authors do not realize that no two applications should have the same Creator Code.

Model: MacBook Pro
AppleScript: 2.11
Browser: Firefox 70.0
Operating System: macOS 10.14

Welcome, James6M.

I tried your script, I saved it, reopened it, and “BlueGriffon” remains “BlueGriffon”. :slight_smile:
Try reinstall application. Maybe the developers fixed the bug. Check first if application is in Applications folder.

Hi James6M.

Yes. That’ll be the reason. It’s the creator code that’s stored in the compiled script. When Script Editor decompiles it later to display the text to you, it uses the first application it finds with that code. One thing you could try would be to include the path to BlueGriffon in the ‘activate’ command. This way, it’s the path, not the creator code, that’s stored in the script. If BlueGriffon’s in your Applications folder:

tell application ((path to applications folder as text) & "BlueGriffon.app") to activate

Another way would be to tell the Finder to open it:

tell application "Finder" to open application file "BlueGriffon.app" of folder "Applications" of startup disk

You can also use IDs instead of names, like this:

tell application id "org.mozilla.firefox" -- Firefox.app
	--your code goes here
end tell

Thanks much!

I take it that KniazidisR’s experience must be a result of saving the script without compiling it? That would explain my not-completely-consistent experience, as well. I don’t really know when a script gets compiled.

Having these multiple options leads a newbie to wonder which is preferred. I found this MacScripter post which seems to favor Shane Stanley’s suggestion. I guess the Bundle Identifier is the new Creator Code.

Not really an AppleScript question:
The duplicate creator code seems like it is just asking from problems, not just in Script Editor. I wonder if it is even possible to get the following line from the above post to work

get bundle identifier of (info for (path to application "BlueGriffon"))

because the application name is auto-corrected before it runs. (Is that compilation? Why does that instantly auto-correct, but

tell application "BlueGriffon" to activate

does not?)

Does anyone here know whether it is safe to manually change the creator code in the Info.plist? I’m not brave enough to test this… (I do have the most updated BlueGriffon version, so re-installation won’t help.)

Not really – creator codes are a remnant from the pre-OS X days, and I doubt there’s much else using them. You’ll find that a lot of apps have a creator code of ???, which is a wild-card. Bundle IDs are the replacement.

Tell blocks are handled differently. It’s complicated (and largely irrelevant).

It’s not – you shouldn’t change anything in an application bundle.

On my machine the following script returns “DIBG” for BlueGriffon, and “MOZB” for Firefox:

get file creator of (info for (path to application "BlueGriffon"))

And… as I see, Script Editor turns not BlueGriffon to FireFox, but FireFox to BlueGriffon. Doesn’t work correct WHEN IS ACTIVE BlueGriffon.app the following:

tell application "Firefox" to activate
get file creator of (info for (path to application "Firefox"))

But as I check, following works correct WHEN IS ACTIVE BlueGriffon.app too:


set myApp to application id "org.mozilla.firefox"

tell application id "org.mozilla.firefox" to activate

get file creator of (info for (path to application id "org.mozilla.firefox"))

And for the record, that article is both very old, and also incorrect. Scripts store tell references as a special kind of descriptor created from an aliasHandle, similar to the way AppleScript aliases (hence the name) are stored. That means names are generally updated if scripts are opened after apps are renamed. However, the code that resolves such aliases was deprecated in OS X 10.8, and although it mostly still works, it will try to resolve based on creator types. And that’s why it’s not a good thing to rely on.

When you use IDs, they are stored as strings and resolved at run-time.