applescriptfinder

AppleScript/Finder not finding the Numbers application


This fragment of a script does a simple check for the existence of Numbers in the Applications folder:

tell application "Finder"
  set AppFolder to folder "Applications" in startup disk as string
  set NumApp to AppFolder & "Numbers"
  set NumExists to (exists NumApp)
end tell

But it doesn't find it. Numbers does exist:

vger:~(128)+>- ls -dl /Applications/Numbers.app/
drwxr-xr-x@ 3 root  wheel  96 18 Sep 13:33 /Applications/Numbers.app/
vger:~(129)+>-

So why does Finder/AppleScript think it doesn't?

This happens on macOS 14.x and 15.x.


Solution

  • Combining the suggestions of @wch1pink, @Mockman and @Ted Wrigley here are two approaches:

    set AppFolder to path to applications folder
    set NumLoc to AppFolder & "Numbers.app" as string
    
    try
        NumLoc as alias
        set NumExists to true
    on error
        set NumExists to false
    end try
    

    The setting of the variable is just for illustration. Or more directly:

    if exists application "Numbers" then
        set NumExists to true
    else
        set NumExists to false
    end if