Mavericks - Tell application "Preview" open PDF - strange permission issue
Solution 1:
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
Solution 2:
This problem is caused by Apple's sandboxing of Preview (and other apps). Preview does not receive an entitlement to access the PDF if you just pass it a string to open. From Apple's release notes:
Compatibility Notes
When sending commands to a sandboxed application, such as TextEdit in OS X Mountain Lion, parameters that refer to files must be of an explicit file-like type and not a bare string, or the target application will not be able to access the file. For example, file "Macintosh HD:Users:me:sample.txt", POSIX file "/Users/me/sample.txt", or the result of choose file would all be acceptable, but the string "/Users/me/sample.txt" would not.
Why does this work for the file in your Downloads folder? When you open a file manually, the application retains the entitlement to open it (in Recents, for instance). Therefore, if you try any file you've opened already, odds are it will work, but it won't work on new files.
To fix, change your code to read:
tell application "Preview"
activate
open POSIX file "/Users/me/Desktop/test.pdf"
end tell