ExifTool Forum

ExifTool => Developers => Topic started by: Rich S on October 13, 2012, 10:11:31 PM

Title: Copy/Paste Metadata from Excel File?
Post by: Rich S on October 13, 2012, 10:11:31 PM
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/

Title: Re: Copy/Paste Metadata from Excel File?
Post by: Phil Harvey on October 14, 2012, 05:33:03 PM
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
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Rich S on October 15, 2012, 12:47:13 AM
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

Title: Re: Copy/Paste Metadata from Excel File?
Post by: Phil Harvey on October 15, 2012, 08:12:23 AM
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
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Rich S on October 15, 2012, 03:00:22 PM
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.
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Phil Harvey on October 16, 2012, 06:39:04 AM
There are also a couple of scripts at the top of the list under the Mac OS X section.

- Phil
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Rich S on October 17, 2012, 03:23:22 AM
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)

Title: Re: Copy/Paste Metadata from Excel File?
Post by: Phil Harvey on October 17, 2012, 08:50:25 AM
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
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Rich S on October 17, 2012, 12:23:11 PM
Thanks again Phil! I'll keep plugging away  :D
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Rich S on October 24, 2012, 02:35:52 AM
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
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Phil Harvey on October 24, 2012, 07:22:31 AM
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
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Rich S on October 24, 2012, 11:31:44 AM
Thanks so much Phil! I'll play with it and see if I can get it to work...
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Rich S on October 26, 2012, 01:49:13 AM
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?

:)
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Phil Harvey on October 26, 2012, 08:00:32 AM
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
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Rich S on October 30, 2012, 12:57:12 PM
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
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Phil Harvey on October 30, 2012, 01:05:01 PM
Hi Richard,

Yes, but you need to do something like quoted form of posix path of FOLDERNAME in your script to convert the folder name to a string you can use in an exiftool command.  (I'm not an expert here, but I recall seeing that in some of the AppleScript samples available from the ExifTool home page.)

- Phil
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Rich S on October 30, 2012, 07:27:27 PM
Tried this:

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


set exiftool_path to "/usr/bin/"
set exiftool_args to "-csv=/Users/richardsc/desktop/cc_pt_automate.csv"
repeat with the_file in source_folder
   set exiftool_args to exiftool_args & " " & quote & POSIX path of the_file & quote
end repeat

do shell script exiftool_path & "exiftool " & exiftool_args


and got the "No file specified" error. The path to the csv file is accurate (cd'd & pwd'd in Terminal), so I have no idea why it isn't finding it. Attached is a screen shot of the script & the error...

Tempted to just give up at this point and manually copy/paste the metadata in LR. Wasting too much of your time.

Thanks again,

Richard


Title: Re: Copy/Paste Metadata from Excel File?
Post by: Phil Harvey on October 31, 2012, 07:30:34 AM
The problem is what you are doing in your loop.  If you just pass the folder name to exiftool it should work:

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

set theFolder to quoted form of POSIX path of source_folder
set exiftool_path to "/usr/bin/"
set exiftool_args to "-csv=/Users/richardsc/Desktop/cc_pt_automate.csv"

do shell script exiftool_path & "exiftool " & exiftool_args & " " & theFolder


I figured out what was going on by adding ""echo " & " at the start of the shell script to see what the command line looked like. (of course, echo strips the quotes, but you can't have everything)

- Phil
Title: Re: Copy/Paste Metadata from Excel File?
Post by: Rich S on November 01, 2012, 04:39:55 PM
Holy shit. That was the sexiest thing I've ever seen (okay, maybe not, but close!!!)

It worked Phil! You have attained god status in my book. Hours of labor intensive work reduced to a few mouse clicks.

Thanks so much :)

Richard

http://www.richardschmon.com/