Reputation: 1098
I struggle with a basic file operation in Apple Script. A pdf is (successfully) written in the script like this:
theDocument's writeToURL:targetFile
Now I want to open the file in Preview like this:
tell application "Preview"
activate
open targetFile
end tell
I also tried this:
tell application "Preview"
activate
open POSIX path of targetFile
end tell
to no avail. I somehow seem to lack an understanding how to get the path to a given file.
What am I missing?
Upvotes: 0
Views: 450
Reputation: 176
Your code doesn’t show what targetFile
is, but assuming from the first line it’s an NSURL
you need to convert it to an AppleScript file type before passing it to Preview’s open
command:
set targetFile to targetFile's |path|() as string as POSIX file
AppleScript’s Apple event bridge doesn’t accept ObjC classes, only native AS types.
Upvotes: 1