I have the following AppleScript that checks whether the file test.csv exists on the desktop. When I run the code, the following message appears: Script Error: Can’t get file ‘Macintosh HD:Users:adam:Desktop:test.csv’.
set fileTarget to (path to desktop as text) & "test.csv"
if file fileTarget exists then
display dialog "it exists"
else
display dialog "it does not exist"
end if
Can you please advise where the error might be? Yes, the file really exists on the desktop. I have checked it three times."
Only the Finder
and System Events
know whether a file exists or not
set fileTarget to (path to desktop as text) & "test.csv"
tell application "Finder"
if file fileTarget exists then
display dialog "it exists"
else
display dialog "it does not exist"
end if
end tell