Let me hedge a bit on this. One of the things that’s happened over the past few releases of macOS is that many enums and constants have been renamed. The new names follow a more consistent pattern, and are designed to work better with Swift.
NSEventModifierFlagCommand is an example of this – before 10.12,
NSCommandKeyMask was used for the same thing.
This presents a problem for AppleScriptObjC, because unlike Objective-C, the values are resolved at run-time, not compile time. So if you use
NSEventModifierFlagCommand in a script and try to run it on a system pre-10.12, you will get an error – it will be unknown.
This is why using properties for enums, and letting Script Debugger’s code completion do it for you, is a good idea. In this case, the above code would actually appear like this:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "AppKit"
use scripting additions
-- classes, constants, and enums used
property NSEventModifierFlagCommand : a reference to 1048576
-- other stuff in here
repeat with anEntry in buttonsList
set oneButton to (its addButtonWithTitle:anEntry)
if contents of anEntry = "Quit" then
Now if you run it under an older version of the OS, it doesn’t matter that it won’t know about
NSEventModifierFlagCommand because the script has effectively resolved it at compile time — within the script it’s just a variable.
The only disadvantage to doing it this way is that you need to be conscious of it when you copy and paste into another script or Web site — you need to use the
Copy as Standalone Code command.