AppleScript checking if folder exists causes “AppleEvent handler failed” error -10000

applescript

AppleScript on macOS Mojave and can't work out why this script gives the expected "TRUE" on the first folder, but instead of "FALSE" on the second folder it aborts with the error message:

[error "Finder got an error: AppleEvent handler failed." number -10000 from folder (file "Felix HD:Users:Billy:TESTING:FOLDER2"]

tell application "Finder"

    set targetFolder to POSIX file "/Users/Billy/TESTING/FOLDER1" -- Existing folder

    if exists folder targetFolder then
        say "TRUE"
    else
        say "FALSE"
    end if

    set targetFolder to POSIX file "/Users/Billy/TESTING/FOLDER2" -- Non-existing folder

    if exists folder targetFolder then
        say "TRUE"
    else
        say "FALSE"
    end if

end tell

Best Answer

I think I found the answer: removed the word 'folder' from the if statements and now it works!

If anyone could confirm this is the proper syntax that would be great.

tell application "Finder"

    set targetFolder to POSIX file "/Users/Billy/TESTING/FOLDER1" -- Existing folder

    if exists targetFolder then
        say "TRUE" -- result!!
    else
        say "FALSE"
    end if

    set targetFolder to POSIX file "/Users/Billy/TESTING/FOLDER2" -- Non-existing folder

    if exists targetFolder then
        say "TRUE"
    else
        say "FALSE" -- result!!
    end if

end tell