Script to add keywords to file name?

Discussion regarding all scripting related questions
Please DO NOT post to this thread anything that is not directly related to scripting of Capture One.

Script to add keywords to file name?

Postby AdamTracksler » Tue Mar 13, 2018 7:26 pm

I have a catalog of products, and I would like to be able to export the keywords (the individual product name) when I export the images. I could do this on Lightroom, but cannot seem to do this in C1. I hoped maybe there was a script I could run....
AdamTracksler
 
Posts: 5
Joined: Thu Jul 30, 2015 11:26 pm

Re: Script to add keywords to file name?

Postby Eric Nepean » Wed Mar 14, 2018 3:22 am

AdamTracksler wrote:I have a catalog of products, and I would like to be able to export the keywords (the individual product name) when I export the images. I could do this on Lightroom, but cannot seem to do this in C1. I hoped maybe there was a script I could run....

In the export menu you can add Metdata information, but not keywords, to the image name.

If each of your images has only 1 keyword to describe the product, what I would do is run an Applescript to copy the keyword of each image to a Metadata field you don't normally use (e.g. "Getty original filename") ... or perhaps a Metadata field which is approriate for this use (e.g. "content headine")

Having done that, you can use the standard features of the export menu to add the Metadata field to the name of the exported image.

I have tested this script
Code: Select all
##{ some code to determine the name of your document  as COPDocName }
set COPDocName to 1 -- quick and dirty approach
tell application "Capture One 11" to tell document COPDocName to tell collection "All Images" to set count_All_Variants to count of every variant

repeat with variantCounter from 1 to count_All_Variants
   tell application "Capture One 11" to tell document COPDocName to tell collection "All Images" to tell variant variantCounter
      set keywordcount to count of keywords
      set variantName to name
      if 0 < keywordcount then
         -- this assumes that there is only 1 keyword
         -- if there are more keywords, you will need to add some code to find the correct keyword (perhaps based on the parent)
         set {KWname, KWparent} to {name, parent} of keyword 1
         set KWparent to KWparent as text
         if KWparent ≠ "missing value" then set KWname to KWparent & " " & KWname -- optionally drop this line
         set content headline to KWname
         log {variantName, keywordcount, "Done"}
      else
         log {variantName, keywordcount, "Not Done"}
      end if
   end tell
end repeat



Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 117
Joined: Sat Oct 25, 2014 8:02 am

Re: Script to add keywords to file name?

Postby AdamTracksler » Mon Apr 30, 2018 3:01 pm

Do I need to modify anything in this script to put the keywords in the Getty original file name? Or is it good to go?
AdamTracksler
 
Posts: 5
Joined: Thu Jul 30, 2015 11:26 pm

Re: Script to add keywords to file name?

Postby Eric Nepean » Tue May 01, 2018 6:08 am

AdamTracksler wrote:Do I need to modify anything in this script to put the keywords in the Getty original file name? Or is it good to go?

The script as written will put the keyword info into the "Content Headline" field.

To put the keyword info into the Getty original filename field, you need to replace the line "set content headline to KWname" by "set Getty original filename to KWname"

The script is written assuming that you only have one keyword for each image. If some or all images have more than 1 keyword, then we have to add something to check each keyword name (or parent) and choose the correct one. But not knowing if you have more than 1 keyword per image, and not knowing how to recognise the appropriate keyword if there is more than 1, I haven't supplied that.

Note that the script as written will only run reliably if you have only one catalog or session open. One could make it reliable even if multiple documents were open, but that would add complexity, and for a beginner in Applescript, that is not a good choice.
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 117
Joined: Sat Oct 25, 2014 8:02 am

Re: Script to add keywords to file name?

Postby AdamTracksler » Tue May 01, 2018 12:43 pm

Most only have one keyword, but there are many that have multiples.

What should I do in that case?
AdamTracksler
 
Posts: 5
Joined: Thu Jul 30, 2015 11:26 pm

Re: Script to add keywords to file name?

Postby Eric Nepean » Tue May 01, 2018 3:09 pm

AdamTracksler wrote:Most only have one keyword, but there are many that have multiples.
What should I do in that case?

Do you want to include all keywords if there are multiples?

If not, we need a way to identify which are the keywords to be used, and which are not
There are two choices
1) Define a rule to recognise the valid key words for this purpose
2) Define a rule to recognise the invalid key words for this purpose

More than 1 rule is also possible.

Then we can make a simple loop to check all keyords of a variant and either reject the invalid ones or accept the valid ones.

One way of recognition is a character sequence e.g. contains the sequence "rem", starts with "_", starts with a capital letter

Another way of recognition is if you have hierarchical keywords. The keywords are recognised according to their parents are accepted or not accpted.

Another way is to make a list of keywords to be rejected. This is practical if the list is short and does not change much.

If someone was absolutely new to your system, and limited intelligence, how would you explain twhich are the keywords to be used or not used?

If you can state a few simple rules, I can write some simple Applescript to impleement them.
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 117
Joined: Sat Oct 25, 2014 8:02 am


Return to Scripting



Who is online

Users browsing this forum: No registered users and 1 guest