Applescript File Permissions with Preview

When I have Applescript tell Preview to open a newly created image file, like this:

tell application "Preview" to open scan_folder & "6 L.tif"

Preview pops up the message: "The file "6 L.tif" couldn't be opened because you don't have permission to view it."

However if I open it manually from Preview, or have Finder open it, it works OK.

Stranger yet, after the file has been opened one time by Preview, then I don't get the error when Applescript tells Preview to open it.

The file permissions are set to "Read & Write" when the file is created, and are unchanged after it is opened manually.

How can I have Applescript tell Preview to open newly minted image files?

iMac G5, Mac OS X (10.4.2)

Posted on May 15, 2016 9:58 AM

Reply
4 replies
Sort By: 

May 15, 2016 2:15 PM in response to Paul Cardinale

We need to see the exact command your issued here: Copy & paste to replay.


I click on advanced. Click on blue >> > Syntax Highlighting > plain


User uploaded file


-------------------------------------------------------


Here is how I used the open command.


I'd try the full path to the file.


type in open followed by a space. Then drag the file to the terminal window and drop.


mac $ pwd
/Users/mac
mac $ open  /Users/mac/Desktop/all\ Screen\ Shots/Screen\ Shot\ 2016-05-15\ at\ 2.32.20\ AM.png
mac $
Reply

May 15, 2016 4:27 PM in response to Paul Cardinale

To post code what you see in the terminal [ or you could post an image of what you see. ]


-- click on "Use advanced editor."

User uploaded file


-- click on the >> that are in blue.


User uploaded file

Your will see:

User uploaded file


-- click on syntax highlighting


-- click on plain. Causes a one line input box to appear.





-- paste you code into the input box.

Reply

May 15, 2016 2:34 PM in response to rccharles

You say to "click on advanced ..." but you didn't specify a context. I can't find anything labeled "advanced" in the script editor, nor in the terminal. What are you referring to? When I open a file manually, I do it by either double-clicking on it in the Finder, or from the menu in Preview, selecting File -> Open ...

Reply

May 15, 2016 7:58 PM in response to Paul Cardinale

Hello


Firstly, I doubt you're actually using OS X 10.4.2 as your profile states. Please update it.


Now there're couple of things to try.



1) Refine your AppleScript script as follows, provided scan_folder is HFS path:



tell application "Preview" to open (scan_folder & "6 L.tif" as alias)




Or as follows, provided scan_folder is POSIX path:



tell application "Preview" to open (scan_folder & "6 L.tif" as POSIX file)




This is because in recent AppleScript under sandboxed environment, explicit and strict file referencing is imposed.



2) Try the following command in Terminal and see how it works or not:



#!/bin/bash open -b com.apple.Preview /path/to/a.tif




3) Run the following command in Terminal before and after opening the file and see if there's any difference in output.



#!/bin/bash ls -al@Oe /path/to/a.tif




If the outputs are the same and there's extended attribute com.apple.quarantine, I suspect that com.apple.quarantine is the cause and you may delete it by xattr(1) command before opening the file, such as -



#!/bin/bash xattr -d com.apple.quarantine /path/to/a.tif




Regards,

H

Reply

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Applescript File Permissions with Preview

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.