Skip to main content

⚠️ Please note that this topic or post has been archived. The information contained here may no longer be accurate or up-to-date. ⚠️

Adding Image Name to the Headline

Comments

9 comments

  • Rick Allen

    The name property of an image in Capture One contains the frame counter so you'd need to split out that part from the filename. How you do that could have a number of strategies.

     

    If for instance you use a simple underscore or dash etc. i.e. filename_00001 you could use the below code.

    Hope this helps

    use AppleScript version "2.4" -- Yosemite (10.10) or later

    use framework "Foundation"

    use scripting additions

    tell application "Capture One 23"
    tell current document
    set theVars to variants whose selected is true
    repeat with aVar in theVars
    set varName to name of aVar
    -- change delimiter to suit
    if varName contains "_" then
    set theHeadline to item 1 of my theSplit(varName, "_") as string
    end if
    set content headline of aVar to theHeadline
    end repeat
    end tell
    end tell

    on theSplit(theString, theDelimiter)

    -- save delimiters to restore old settings
    set oldDelimiters to AppleScript's text item delimiters
    -- set delimiters to delimiter to be used
    set AppleScript's text item delimiters to theDelimiter
    -- create the array
    set theArray to every text item of theString
    -- restore the old setting
    set AppleScript's text item delimiters to oldDelimiters
    -- return the result
    return theArray
    end theSplit
    1
  • LYNNETTE MAGER WYNN

    Thank you so much for your help, Rick! This solution is working perfectly! I’m now wondering if it’s possible to modify the script further to place the prefix (7 digits, decimal point, 3 digits) in the headline, and then use the suffix (e.g., “v1 p1”) to generate keywords. We’d like to add all relevant keywords automatically. For instance, if the image is named "1010021.178 v1 p1," I’d like the script to set "1010021.178" as the headline and use “v1” and “p1” as keywords. Is there a way to extend the script to do this? Thanks again for all your help!

    0
  • LYNNETTE MAGER WYNN

    I think I figured it out by combining your script with one for keywording.

     

    use AppleScript version "2.4" -- Yosemite (10.10) or later use framework "Foundation" use scripting additions tell application "Capture One 22" tell current document set theVars to variants whose selected is true repeat with aVar in theVars set varName to name of aVar -- Split the filename at the underscore set nameParts to my theSplit(varName, "_") -- Set the headline (everything before the underscore) if (count of nameParts) > 1 then set theHeadline to item 1 of nameParts set content headline of aVar to theHeadline end if -- Set the keyword (everything after the underscore) if (count of nameParts) > 1 then set keywordText to item 2 of nameParts -- Remove file extension if present set dotPosition to offset of "." in keywordText if dotPosition > 0 then set keywordText to text 1 thru (dotPosition - 1) of keywordText end if -- Add the keyword to the variant tell aVar if not (exists keyword keywordText) then make new keyword with properties {name:keywordText} end if end tell end if end repeat end tell display dialog "Batch headline and keywording completed!" buttons {"OK"} default button "OK" end tell on theSplit(theString, theDelimiter) -- save delimiters to restore old settings set oldDelimiters to AppleScript's text item delimiters -- set delimiters to delimiter to be used set AppleScript's text item delimiters to theDelimiter -- create the array set theArray to every text item of theString -- restore the old setting set AppleScript's text item delimiters to oldDelimiters -- return the result return theArray end theSplit

    0
  • Sheldon Sabbatini

    This script is great!

    Rick Allen any idea how to modify the script to copy the image folder name into the headline instead of the filename into the headline?  

     

    I'm struggling trying to find the paths to the various metadata fields in C1.  Especially the Next Capture Metadata fields in Studio/Enterprise.

     

    Thoughts?

    0
  • Rick Allen

    To modify script to add the images folder name to headline see below.

    The idea behind Next Capture Metadata is to have an event (like creating a new capture folder) that then ets the NCM fields before the images are captured into that folder. I am developing an application that I'll release in the next few weeks that is triggered by a keyboard shortcut that allows you to set the name of the new capture folder, set the next capture naming and apply predefined (configurable NCM fields). If youre interested email me at dev at requiredtech dot io for a beta version.

    use AppleScript version "2.4" -- Yosemite (10.10) or later

    use framework "Foundation"

    use scripting additions




    tell application "Capture One 23"

    tell current document

    set theVars to variants whose selected is true

    repeat with aVar in theVars

    set varPath to file of aVar as string

    set theHeadline to item -2 of my theSplit(varPath, ":") as string

    set content headline of aVar to theHeadline

    end repeat

    end tell

    end tell







    on theSplit(theString, theDelimiter)




    -- save delimiters to restore old settings

    set oldDelimiters to AppleScript's text item delimiters

    -- set delimiters to delimiter to be used

    set AppleScript's text item delimiters to theDelimiter

    -- create the array

    set theArray to every text item of theString

    -- restore the old setting

    set AppleScript's text item delimiters to oldDelimiters

    -- return the result

    return theArray

    end theSplit
    0
  • Walter Rowe
    Moderator
    Top Commenter

    We can get the folder of a variant's image file without using text splitting by asking Finder to tell us. This is also 100% fool proof.

    # get the alias to the disk file
    set thePath to file of theVariant

    # get the POSIX path of the folder containing the image file
    tell application "Finder" to set theFolder to POSIX path of ((container of (thePath as alias)) as string)

    In the code above replace this line:

    set theHeadline to item -2 of my theSplit(varPath, ":") as string

    with this line:

    tell application "Finder" to set theHeadline to POSIX path of ((container of (thePath as alias)) as string)

    No need to use theSplit().

    0
  • Rick Allen

    Apologies I thought the Sheldon wanted the name of the container folder which you could get with this... 

    tell application "Finder" to set theHeadline to name of container of (varPath as alias) -- no need to convert to POSIX path

     

    But interacting with the finder does have a performance cost. Atleast on my system getting the container name via Finder took 2.5sec per 100 images verses .5sec per 100 images. On larger image counts you may have Finder stability issues as well. 

    I dont see why my approach would have reliablility issues as Capture One is giving me the path string to parse.

    0
  • Walter Rowe
    Moderator
    Top Commenter

    Perhaps Sheldon can confirm whether he's seeking the /full/path/to/folder of just the parent folder name. Yes, I concede using Finder has a performance penalty. I've not experienced stability issues with Finder, but scenarios can differ based on internal vs external storage, kind of storage, connection to that storage, etc.

    0
  • Sheldon Sabbatini

    Wow, thanks everyone!

    I love to tinker but I'm VERY beginner at any sort of coding or scripting.  I love the process of figuring it all out but then there are times I get stumped and can't figure out some small thing.

     

    That's probably coding in general...or life I guess.  :)

    Rick Allen I would LOVE to Beta Test and help out, that's a lot of what I'm trying to figure out.  

    0

Post is closed for comments.