Monday, December 9, 2019

#1 2019-06-11 08:41:43 pm

snegaroff
Member
Registered: 2006-04-28
Posts: 8

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.

Offline

 

#2 2019-06-11 09:36:44 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 764

Re: do shell script error

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

Applescript:


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

Last edited by KniazidisR (2019-06-11 09:43:44 pm)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#3 2019-06-12 07:44:51 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 235

Re: do shell script error

FWIW, another way to deal with quoting is:

Applescript:


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:

Applescript:


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

Last edited by peavine (2019-06-12 07:04:09 pm)


2018 Mac mini - macOS Catalina

Offline

 

#4 2019-06-12 09:02:16 pm

snegaroff
Member
Registered: 2006-04-28
Posts: 8

Re: do shell script error

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

Offline

 

#5 2019-06-12 09:55:22 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6064

Re: do shell script error

snegaroff wrote:

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.


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#6 2019-06-13 07:29:53 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 235

Re: do shell script error

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

Applescript:

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:

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?


2018 Mac mini - macOS Catalina

Offline

 

#7 2019-06-13 07:34:21 am

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6064

Re: do shell script error

peavine wrote:

I wonder what Shane is doing differently?



Not storing his photos in iCloud?


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#8 2019-06-13 07:38:25 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 235

Re: do shell script error

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:

Applescript:

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.

Last edited by peavine (2019-06-13 09:22:28 am)


2018 Mac mini - macOS Catalina

Offline

 

#9 2019-06-13 08:43:52 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3670

Re: do shell script error

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 :

Applescript:

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

Last edited by Yvan Koenig (2019-06-13 08:47:23 am)

Offline

 

#10 2019-06-13 09:39:02 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 235

Re: do shell script error

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.

Applescript:

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.

Last edited by peavine (2019-06-15 06:49:45 pm)


2018 Mac mini - macOS Catalina

Offline

 

#11 2019-06-13 05:08:02 pm

Shane Stanley
Member
From:: Australia
Registered: 2002-12-07
Posts: 6064

Re: do shell script error

peavine wrote:

Perhaps this is a Mojave permissions issue.



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


Shane Stanley <sstanley@myriad-com.com.au>
www.macosxautomation.com/applescript/apps/
latenightsw.com

Offline

 

#12 2019-06-16 10:19:27 pm

snegaroff
Member
Registered: 2006-04-28
Posts: 8

Re: do shell script error

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?

Last edited by snegaroff (2019-06-16 10:27:20 pm)

Offline

 

#13 2019-06-17 07:39:45 am

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 235

Re: do shell script error

snegaroff wrote:

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.

Last edited by peavine (2019-06-17 09:07:54 am)


2018 Mac mini - macOS Catalina

Offline

 

#14 2019-06-17 08:26:39 am

Yvan Koenig
Member
Registered: 2006-09-14
Posts: 3670

Re: do shell script error

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

Offline

 

#15 2019-06-17 01:00:45 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 764

Re: do shell script error

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

Applescript:


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


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#16 2019-06-17 06:21:27 pm

peavine
Member
From:: Prescott, Arizona
Registered: 2018-09-04
Posts: 235

Re: do shell script error

KniazidisR wrote:

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


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.

Last edited by peavine (2019-06-17 06:31:24 pm)


2018 Mac mini - macOS Catalina

Offline

 

#17 2019-06-17 09:28:49 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 764

Re: do shell script error

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.

Last edited by KniazidisR (2019-06-17 10:01:54 pm)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

#18 2019-06-18 06:31:59 pm

snegaroff
Member
Registered: 2006-04-28
Posts: 8

Re: do shell script error

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.

Offline

 

#19 2019-06-18 10:19:32 pm

KniazidisR
Member
Registered: 2019-03-03
Posts: 764

Re: do shell script error

snegaroff wrote:

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)

Last edited by KniazidisR (2019-06-18 10:20:20 pm)


Model: MacBook Pro
macOS Mojave -- version 10.14.4
Safari -- version 12.1
Firefox -- version 70.0

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)