do shell script error

Looking for help on why this works in the Terminal…

/usr/local/bin/exiftool -Orientation -n ‘/Users/greg/Pictures/Photos Library.photoslibrary/Masters/2007/Roll 344/DSC_0041.JPG’

…but the following throws up an error message in the Script Editor…

do shell script “/usr/local/bin/exiftool -Orientation -n ‘/Users/greg/Pictures/Photos Library.photoslibrary/Masters/2007/Roll 344/DSC_0041.JPG’”

I assume it has something to do with the fact that Photos Library is a package that requires “Show Package Contents” to show the full path in the Finder.

Any assistance is appreciated. Thanks.

Probably you need escape internal quotes (which is inside external quotes) with AppleScript’s way (") instead of command line’s way ('). Always. Try this:


do shell script "/usr/local/bin/exiftool -Orientation -n \"/Users/greg/Pictures/Photos Library.photoslibrary/Masters/2007/Roll 344/DSC_0041.JPG\""

FWIW, another way to deal with quoting is:


do shell script "/usr/local/bin/exiftool -Orientation -n " & quoted form of "/Users/greg/Pictures/Photos Library.photoslibrary/Masters/2007/Roll 344/DSC_0041.JPG"

Or, perhaps to make things a bit clearer:


set myFile to "/Users/greg/Pictures/Photos Library.photoslibrary/Masters/2007/Roll 344/DSC_0041.JPG"

do shell script "/usr/local/bin/exiftool -Orientation -n " & quoted form of myFile

This won’t address the package issue mentioned by the OP (if there is an issue).

Thanks all for the replies. I tried them all, but unfortunately, they result in “Error: Error opening file.”

Because this exact syntax works for other visible files, I’m thinking it must be something with the unique status of the package contents of the “Photos Library.”

I don’t think so. At least, it works for a Photo Library image here.

I created a “Photos Library” and placed one photo in it. I then ran the following in a terminal window:

/usr/local/bin/exiftool -Orientation -n “/Users/bob/Pictures/Photos Library.photoslibrary/Masters/2019/06/13/20190613-130451/Willlow Creek Snow.jpg”

This returned “Orientation 3”.

I then ran the above command line in an AppleScript as follows

set myFile to "/Users/bob/Pictures/Photos Library.photoslibrary/Masters/2019/06/13/20190613-130451/Willlow Creek Snow.jpg"

do shell script "/usr/local/bin/exiftool -Orientation -n " & quoted form of myFile

This returned:

error “Error: Error opening file - /Users/bob/Pictures/Photos Library.photoslibrary/Masters/2019/06/13/20190613-130451/Willlow Creek Snow.jpg” number 1

I then placed the photo in a regular folder and ran the following in an Applescript:

set myFile to "/Volumes/Samsung SSD/Working/Willlow Creek Snow.jpg"

do shell script "/usr/local/bin/exiftool -Orientation -n " & quoted form of myFile

This returned “Orientation 3”.

So, my experience is the same as the OP and I wonder what Shane is doing differently?

Not storing his photos in iCloud?

iCloud is disabled on my computer. I’m running Mojave and version 11.21 of exiftool.

BTW I ran the following and it showed no files inside the photo package:

set myPhoto to (choose file with showing package contents)
set myFile to POSIX path of myPhoto
do shell script "/usr/local/bin/exiftool -Orientation -n " & quoted form of myFile

The files/folders in the photo package are visible in the Finder.

Running 10.3.6 and using a local library (never used iCloud) exiftool version 11.51 returned correctly the wanted info : “Orientation : 1”

The code used was :

set leChemin to (path to pictures folder as text) & "Photos Library.photoslibrary:Masters:2015:10:10:20151010-200530:P1010002.JPG"
set myFile to POSIX path of leChemin
do shell script "/usr/local/bin/exiftool -Orientation -n " & quoted form of myFile

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) jeudi 13 juin 2019 16:43:45

Perhaps this is a Mojave permissions issue. I ran the following script as a standalone application, and, after prompting for permission to access my photos, the script ran correctly. The exact same script if run from within the script editor returned the error-opening-file message.

set myFile to "/Users/bob/Pictures/Photos Library.photoslibrary/Masters/2019/06/13/20190613-141651/Willlow Creek Snow.jpg"

set theOrientation to (do shell script "/usr/local/bin/exiftool -Orientation -n " & quoted form of myFile)

display dialog theOrientation

Edit 2019-06-15. The OP has not provided enough information to answer his/her original question with certainty but it appears the answer is 1) quoting in the AppleScript is not correct, and 2) Mojave permission is required by the AppleScript to access the OP’s photos.

Could be. I ran it from Script Debugger, and in Preferences → Privacy → Photos, Script Debugger appears and is checked.

Thanks all for the replies. Truly appreciated.

I have not gotten the script to work yet, but it seems reasonable that Mojave permissions is the culprit.

I had previously added Script Editor to the list under Preferences>Security & Privacy>Privacy to “Allow the apps below to control you computer.” Apparently this isn’t enough. Is there something else I might script or do to allow access to the “Photo Library” via the Script Editor?

I know how to do what you want but I don’t know if it’s a good idea. Go to…

System Preferences > Security & Privacy > Privacy

…and add Script Editor to “Full Disk Access”. I ran some tests and after doing this Script Editor has access to Photos.

On my machine, Terminal is in the list of applications allowed to apply upon files.
Is it in your own list ?

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) lundi 17 juin 2019 16:26:31

This worked fine only after I give full disk access permission to exiftool itself:


set myFile to "/Users/123/Pictures/Photos Library.photoslibrary/Masters/2019/06/13/20190613-033913/AQDS0_Fotor.png"

set theOrientation to (do shell script "/usr/local/bin/exiftool -Orientation -n " & quoted form of myFile)

display dialog theOrientation

I just tried this again, and the script worked fine as long as Script Editor had full disk access. Exiftool wasn’t in full disk acess or photos either. I wonder why the difference.

Yes you are right. It turns out that in my settings the Script Editor also had full disk access. As soon as I removed it from the settings, the script again gave an error. But what is interesting: for this test I disabled access to all programs except exiftool and in the Script Debugger everything works fine, unlike the Script Editor. This leads to a logical conclusion that the problem is in the Script Editor, and not in Mojave as a whole.

Now, about the security question you asked. On this question, Apple gives a clear answer: giving permissions to individual small applications is safer than multi-functional applications. This means: in our case it is better to give the permissions to full disk access to the exiftool utility, as I did, and not to the Script Editor. Better yet, save the script as an application and give the permissions to full disk access only to it. Since the application can not change anything on the disk (it only reads) - this is the safest choice, which Apple recommends.

This is the difference.

Bingo.

Giving full disk access to both Script Editor and ExifTool was the key.

Sincere thanks to all who took the time to investigate and reply.

You did not quite understand us however … It is enough to give the permissions for full disk access to only one of the following:

  1. Script Editor
  2. exiftool
  3. A script saved as an applet.

Both the Script Editor and the exiftool utility have vast possibilities for changing data on the disk. Therefore, the best choice for the safety of your disk data is 3)