Copy/Paste Metadata from Excel File?

Started by Rich S, October 13, 2012, 10:11:31 PM

Previous topic - Next topic

Rich S

Hi there,

Total Noob here :) Started with Applescript earlier this week attempting to automate an incredibly redundant task I have ahead of me. Having solved much of it on my own (parsing text in Excel), I hit a brick wall trying to import that text into a couple of metadata fields in NEF & CR2 files. After the friendly folks at Macscripter pointed me to your amazing tool, I spent the last couple of days poking around here attempting to figure out how I would incorporate it into my current Applescript task.

In a nutshell, I need to copy unique text from two columns of individual cells in Excel, and paste each into the IPTC "title" and "description" fields of each raw file. I will need to apply this to batches of up to 120 files and in the coming months, I will be repeating this task hundreds if not thousands of times...

So far I have figured out that I need to run a shell script to fire up Exiftool, but the actual pasting and coding part is alluding me.

Any help would be greatly appreciated.

Thanks,

Richard Schmon
http://www.richardschmon.com/


Phil Harvey

Hi Richard,

I can't help with the text parsing, but there are a number of different ways you can send this information to exiftool.  If you can format this in CSV or JSON format, exiftool can import these files.  Alternatively you could just write an argument file and use the -@ option.  There are examples of calling exiftool from AppleScript on the exiftool home page if you need them.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Rich S

Hi Phil,

Thanks for your help! After digging around and finding this post: http://bit.ly/SV9jhN , I have reconfigured my script to put the image file paths under the "SourceFile" heading and the appropriate tags under the "Title" and "Description" headings in Excel. The script then then saves the CSV file to my desktop. From there, I would like the script to run exiftool, importing the CSV file and applying the metadata to the files.

I have been trying to run it in Applescript like this:

do shell script exiftool -csv="test.csv"

and I get the Applescript Error - Can't make current application into type string.

Thanks again,

Richard


Phil Harvey

Hi Richard,

Did you take a look at the AppleScript examples on the ExifTool home page (look under the Additional Resources for Mac OS X)?  I think they may help here.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Rich S

Hi Phil,

Thanks again for your time. The only mention of Applescript on the home page is the "sample AppleScript to extract tags into AppleScript record" script download under the "Programming" heading. Are these the scripts you're referring to?

If so, I'll give them a look see, and see if that code points me in the right direction.

Phil Harvey

There are also a couple of scripts at the top of the list under the Mac OS X section.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Rich S

Pored over them today looking for lines I could amalgamate to no avail. My script is working perfectly so far and exports a .csv file to the image folder. When I run the following code:

do shell script / usr / bin / exiftool - csv = "/Volumes/Yoda/TrickyDick/Pictures/PT-8003/CC_PT_Automate.csv"

I get the following error: "Can't make current application into type string." Tried running it with and without the full paths with no luck either.

Ran Exiftool in terminal and it worked fine. Seemed very easy for the user at the top of this thread to tag his keywords from a csv file using exiftool: https://exiftool.org/forum/index.php/topic,3544.msg16096.html#msg16096

Just can't call it in Applescript. (tried calling terminal though Applescript but not sure how to specify the destination directory)

Does the csv file have to be located in the image directory? I know Applescript is a simpleton's coding language but for a noob it's easier to understand. What kills me is that the answer could be achieved in about 1/100th the number of keystrokes we've made in this thread.

Thanks for your help Phil,

Richard "my brain hurts" Schmon

(my csv file is attached, as is the ugly, but functional script I have written so far)


Phil Harvey

The .csv file can be anywhere.  You just need to specify the directory.

I don't have time right now to look at your script, but I will when I get back home in 2 days.  Until then, you may have better luck posting in an applescript forum.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Rich S

Thanks again Phil! I'll keep plugging away  :D

Rich S

Okay, officially losing my mind. Spent a nice chunk of my day today manually copying and pasting text from Excel into the "Title" and "Caption" metadata fields of hundreds of files in Lightroom. Does anyone on this forum know how to call exiftool from Applescript and aapply the attached CSV to a folder of DNG files? Do I call exiftool from Applescript through Terminal?

As stated in previous posts, I've successfully automated a huge amount of parsing filenames (to conform to a strict naming convention) using Applescript & Excel. I would love to be able to drop one more bit of script at the end to call exiftool, embed text in these two tags instead of doing the rest manually.

As of now I am running this in Applescript:

do shell script "/usr/bin/exiftool -csv= /users/richardschmon/desktop/CC_PT_Automate.CSV"

and I get error codes ranging from "" to 'File not found: = 1 image files read 1 files could not be read' if I put a space between the CSV & the =.

Pardon my noobness. Just really tired and willing to try anything to avoid wasting so much of my time. I know it's just a couple of simple changes, and the final script will be shorter than this sentence.

Any Applescript + ExifTool users out there?

Thanks,

Richard

Phil Harvey

Hi Richard,

There should be no spaces are the equal sign (before or after).

Also, the exiftool command requires one or more file or directory names.  It doesn't process files named in the CSV, it processes files named on the command line then looks them up in the CSV to get the metadata.  So you should probably add "-ext dng ./Users/richardschmon/Pictures/PT-9094" to your command.  Also, the way your path is specified in the CSV file you must run this command from the root directory.  It would be better if you used "/Users/richardschmon/Pictures/PT-9094", then your working directory wouldn't matter.

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Rich S

Thanks so much Phil! I'll play with it and see if I can get it to work...

Rich S

Okay, I have the csv file in the same folder as the dng files I am hoping to tag (PT-9094). In Applescript I am making the following command:

do shell script "usr/bin/exiftool -csv='tricky dick/users/richardschmon/pictures/PT-9094/CC_PT_Automate.CSV' -ext dng"

and I get the Applescript error:

Error opening CSV file 'tricky dick/users/richardschmon/pictures/PT-9094/CC_PT_Automate.CSV'
No file specified

I know this must be something silly I am buggering up inOSX/ Applescript and nothing to do with exiftool, but here it is anyway.

There can't be very many good photographers out there who are good coders right?

:)

Phil Harvey

What is the full, absolute path specification for your CSV file?

(in the Terminal, "cd" to the directory then type "pwd")

If you use the full path (beginning with a "/"), it should work.

Similarly, you should specify "/usr/bin/exiftool"

- Phil
...where DIR is the name of a directory/folder containing the images.  On Mac/Linux/PowerShell, use single quotes (') instead of double quotes (") around arguments containing a dollar sign ($).

Rich S

Hi Phil,

I am hoping to insert the exiftool command onto my script which calls to the image folder via a "choose folder" dialogue at the beginning of the script:


tell application "Finder"
   activate
   set source_folder to (choose folder with prompt "Choose PT Folder")
   open source_folder
end tell

The script then copies/pastes the paths of each file into the SourceFile column and the metadata into the following two columns. After that it parses the text in each cell to fit our naming convention. Ideally, I would be able to point Exiftool to that folder, as it will be different each time I run. My goal is to make this whole process run as one script. So far I have been successful.

Is there a way to call the "source_folder" in the above snippet?

Thanks again,

Richard