Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

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

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 $

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

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 ID.