Mac – Mavericks – Tell application “Preview” open PDF – strange permission issue

applescriptpermissionpreviewtime-machine

I have recently moved a large research collection of PDF files, from a Snow Leopard 10.6.8 TimeMachine disk, to my new rMBP (to the internal flash storage). I did this manually, not through the TimeMachine interface. The rMBP runs Mavericks 10.9.3.

When I double click the PDFs, they open without a problem in Preview.

But, when I write a small AppleScript to open one, for example:

tell application "Preview"
    activate
    open "/Users/me/Desktop/test.pdf"
end tell

I get the following error on executing the AppleScript:

The file “test.pdf” couldn’t be opened because you don’t have
permission to view it. To view or change permissions, select the item
in the Finder and choose File > Get Info.

I look in Get Info for test.pdf. In the "Sharing and Permissions" tab, it does not matter what I set permissions to, even if all users can Read & Write the file, I still get the error.

Conversely, if I download a PDF from the internet, straight to the desktop, and execute the applescript to open it, it opens in Preview without a problem.

(p.s. I need to open PDF by AppleScript, as part of a larger system I have, I am not just doing it for fun!)

Best Answer

for me do shell script.. failed, but this one below worked.

set filepath to POSIX path of "Users:student:Desktop:Yourfile.pdf" try set command to "open " & quoted form of filepath do shell script command end try

Note: Instead of ":" for file path I used "/", a modification one can try.

Source of Code: MacRumors