Search code examples
macosapplescriptnsimageapplescript-objc

How to get NSImage.Name in AppleScriptObj


How to get NSImage.Name.cautionName

in AppleScriptObj. I tried:

set cautionName to aN of NSImage.Name

but that does not work.


Solution

  • It looks like what you are after is NSImageNameCaution, which is a constant for the name of a system image. Your example (and link) appear to be using Swift, changing the documentation language to Objective-C gives you the proper term.

    AppleScriptObjC uses names from the Objective-C documentation (it also does not use dot notation), so it would be something like:

    use AppleScript version "2.4" -- Yosemite (10.10) or later
    use framework "AppKit"
    use scripting additions
    
    # get the name
    set imageName to (current application's NSImageNameCaution) as text
    # get the image
    set theImage to current application's NSImage's imageNamed:(current application's NSImageNameCaution)