Is there a way to edit IPTC data of an image with AppleScript?

Hi,


I'm looking for a way to batch-edit the IPTC data from images. Is that somehow possible with Applescript? If so, could someone point me to a direction?


(I fond a script working wit Graphic Converter in another thread, but that didn't work.)


Thanks,

p.

Posted on Apr 21, 2014 11:30 AM

Reply
20 replies

Apr 22, 2014 3:51 AM in response to Frank Caggiano

Thanks Frank, I came across that in my research but it is a command line tool and therefor beyond my skills. 😟


What I am trying to achieve is to copy the content of one IPTC caption field to the keywords field.


The reason is that I export Photos from Aperture. There, my keywords (e.g. furniture, chair, wood...) are in the caption field. The acutal "keywords" field holds the photo management tags like "project, edit, final, export" etc.. So, after exporting to jpeg, I need to replace them and it would be nice to do that automated somehow.

Apr 22, 2014 6:11 AM in response to papalapapp

Exiftool, to do a simple copy of data like this would be fairy simple to setup but if you are doing this with Aperture it is possible to do it from there also.. How much Applescript/command line experience do you have? Do you need a point in the right direction for this or more?


I am assuming you do not what the change to the IPTC fields to appear in Aperture, only on the exported version. Also is this a one time thing or will it be your permanent workflow?

Apr 22, 2014 6:51 AM in response to papalapapp

Actually it looks like exiftool would be the way to go.


Once the files are exported you run this


exiftool -keywords= -tagsfromfile @ -caption-abstract IMG_0401.jpg


from the terminal. The filename at the end, IMG_0401.jpg, would of course change for your actual files. And this could be bundled into a shell script or Applescript to run through all files in a folder.


Why not install Exiftool and try the above command on a file or two to see if it does what you want.


Post back when you've given it a try.


regards

Apr 22, 2014 7:22 AM in response to Frank Caggiano

I'm looking for a permanent solution. At the moment I copy & paste them manually which is very time consuming.


My Terminal skills are limited to opening a Terminal window and paste something at the end of the line. But I don't understand what's going on there.


In Applescript I am a beginner but I would be willing do dig in deeper.


Thanks for your suggestion! I tried it and the result is: "1 image files updated". I guess it might need some tweaking because in Preview the keywords field disappears after the edit. Re-importing the jpeg to Aperture shows an empty keywords field. Opening the jpeg in GraphicConverter still shows the old keywords.


I don't know what a shell script is, but if this exiftool-command could be implemented in an Applescript, that would be interesting. I would create a loop and save it as an app to just drop the images on to.

Apr 22, 2014 7:33 AM in response to papalapapp

Interesting, it worked for me at least for the way i understand what you are trying to do.


Could you post on-line somewhere, dropbox would be good, one of the exported versions that you want modified. If we can get exiftool to do this it will be the easiest solution.


regards


Message was edited by: Frank Caggiano - Silly question but i have to ask, you are exporting the metadata with the image correct?

Apr 22, 2014 7:58 AM in response to papalapapp

For some reason the command I posted above seems to be a bit squirrelly, sometimes it does not work for me here either.


Try this one instead


exiftool '-keywords<caption-abstract' IMG_1444.jpg


This should duplicate the caption into the keywords leaving the caption as is. If you want to remove the caption the do


exiftool '-keywords<caption-abstract' -caption-abstract= IMG_1444.jpg


This will copy the caption to the keywords and delete the caption.


See how they work for you.

Apr 22, 2014 10:59 AM in response to Frank Caggiano

Frank, maybe you could give me a hand here. I'm building the basic script cycling through the dropped files. But I don't know how to best implement the terminal command.


In each cycle, I would set the file path as a variable and then compose the terminal command in order to execute it with "do script".


But "set x to path of eachFile" doesn't work: <<class ppth>> of alias "(path shows here)" could not be read. Any ideas how to do that better?


on opentheFiles


repeatwitheachFileintheFiles


set x to path of eachFile


tell application "Terminal"

activate

do script "hello" (Exiftool command will be here)

closewindow 1

end tell


end repeat

end open

Apr 22, 2014 12:28 PM in response to papalapapp

Try this


on opentheFiles

repeat with eachFile in theFiles


set x to POSIX path of eachFile


do shell script "exiftool '-keywords<caption-abstract' " & x

end repeat

end open


It runs the command that just copies the captions to the keywords and leaves the captions intact. Of you want to delete the captions change the exiftool part.


This workflow might work better as a folder action rather then a drop script. That is you could setup a folder so that anytime a file is added to it the script would run.


regards

Apr 23, 2014 11:49 AM in response to Frank Caggiano

Awesome! It just works. Only two thinks I want to point out (which I don't mind actually):


- The original files get the appendix "_original" attached to the file type instead of the file name (filename.jpg_original). But I guess that's an exiftool thing.

- The path to the processed files can't have spaces in the folder names. That throws an error "File not found".


I would prefer to keep it as a drop script because it's more obvious for my workflow. Usually I export to different locations.


Thanks a lot for your help!

Apr 23, 2014 12:29 PM in response to papalapapp

Ok the second problem is easy


change

set x to POSIX path of eachFile

to

set x to quoted form of (POSIX path of (path to desktop as text) & eachFile)


This will quote the names to the shell so spaces and other weird shell chars won't cause an error.


The first thing I'm not so sure about. Exiftool wasn't adding a suffix to the file when I did it here and it seems odd that it would add _original as the author would realize that would mess up the file type.


Are you sure you are not running anything else in the workflow? You're just exporting from Aperture to a folder and running this script, right? Are you sure the filenames coming out of Aperture do not have the _original attached already?


I'll look at Exiftool again to make sure it's not something in there. BTW when you installed exiftool did you do the source install or the dmg install?

Apr 24, 2014 2:35 AM in response to Frank Caggiano

Somehow that doesn't work. It says "File not found" while showing the path twice daisychained with " / " and " : ".


User uploaded file



Frank Caggiano wrote:



Are you sure you are not running anything else in the workflow? You're just exporting from Aperture to a folder and running this script, right? Are you sure the filenames coming out of Aperture do not have the _original attached already?


I'll look at Exiftool again to make sure it's not something in there. BTW when you installed exiftool did you do the source install or the dmg install?


I export from Aperture and the files show as "filename.jpg". Aperture creates a folder at export and places the images there. When I run the script, Mail and Safari are open but other than that there is nothing else going on.


Interesting observation when using your first solution:
( setxtoPOSIX pathofeachFile )



1. Export from Aperture to a folder, e.g. Desktop/2014-04-24/filename.jpg

2. Duplicate that folder, resulting in: Desktop/2014-04-24 Copy/filename.jpg

(notice the space before "Copy")

3. Drag the duplicate files (not the folder itself) on to the script

4. An error says "File not found"

5. At the same time, the files in the original folder get processed

Apr 24, 2014 5:53 AM in response to papalapapp

Ok, sorry I copied the wrong updated code into my last post,


It should be

set x to quoted form of (POSIX path of eachFile)


that should fix the problem with spaces in the folder and/or filenames.


Need to look into the other problem, this fix might address that also so try this in the meantime and let me know.


regards


Message was edited by: Frank Caggiano - BTW how did you install exiftool. Not sure it has a bearing on this but it would be good to know.

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.

Is there a way to edit IPTC data of an image with AppleScript?

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