Repeat with applying metadata sometimes doesn't apply

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

Repeat with applying metadata sometimes doesn't apply

Postby SeanMurp » Thu Aug 03, 2017 5:55 pm

I have a strange issue with applying metadata after a batch rename, and unfortunately I only have hearsay evidence of it actually occurring and can't reproduce it myself. Our script (attached below):
    1. Gets the current session name, splits up the name into six parts and sets those as variables. example session name: "17-08-03 modelname AM1 B1 photographername W"
    2. pops up a dialog for the user to paste in a fifteen digit name. ex. "XXXXX1234567890"
    3. Does a batch rename with the name entered.
    4. Repeats through all selected variants and applies the variables into different metadata fields.

The photographers have occasionally run into an issue where they will run the script, paste in the sku and the metadata won't be applied to all of the selected variants. Doesn't happen all the time and if they run the script again they usually have success. I have tested and tested and tested this script and have yet to reproduce the error yet they seem to have it occur over multiple users on different computers. Is anyone able to see anything inherently wrong with the code? Or is there maybe a setting within Capture One we should make sure is checked or unchecked?

Code: Select all
   ------------------------------------------------------------------------------------------------
   --Determine shoot name data and Dialog to Enter BSC
   ------------------------------------------------------------------------------------------------
   
   set progress total steps to 6
   set progress completed steps to 0
   set progress description to "Updating Metadata..."
   set progress additional description to "Preparing to process."
   
   
   tell application "Capture One 10"
      activate
      set sessionName to name of current document
   end tell
   
   set progress additional description to "Updating..."
   set progress completed steps to 1
   --set shootName to trimText(sessionName, ".cosessiondb", "end")
   set {shootName, dbName} to my theSplit(sessionName, ".")
   set {shootDate, modelname, timeOfDay, baynumber, photographerName, businessunit} to my theSplit(shootName, space)
   
   
   --determine studio location
   if sessionName contains "Accessories" then
      set studioLocation to "_off_"
   else
      set studioLocation to "_on_"
   end if
   

   set progress additional description to "Updating..."
   set progress completed steps to 2
   set shootDateShort to do shell script "date +'%Y%m%d'"
   
   tell application "Capture One 10"
      activate
      set bscCorrect to "false"
      repeat while bscCorrect = "false"
         
         set currentBSC to {text returned} of (display dialog "" default answer "" with title "Enter BSC") as text
         
         set characterCount to length of currentBSC
         
         
         if characterCount is greater than or equal to 15 then
            set currentBSC to (characters 1 thru 15 of currentBSC) as text
            set bscCorrect to "true"
         else
            display dialog "The BSC you entered is too short.  Try again."
            set bscCorrect to "false"
         end if
      end repeat
      
   end tell
   

   set progress additional description to "Updating..."
   set progress completed steps to 3
   ------------------------------------------------------------------------------------------------
   --Check for BSC previously used
   ------------------------------------------------------------------------------------------------
   --Configf file to write values to
   set shootList to "/Volumes/WORKING/In_Progress/" & shootName & "/shootList.plist"
   
   
   tell application "System Events"
      --try
      tell property list file shootList
         if property list item currentBSC exists then
            set BSCexists to button returned of (display dialog "This BSC has been used previously.  Would you like to continue or stop?" buttons {"Continue", "Stop"})
            if BSCexists = "Stop" then
               error number -128
            end if
         else
            make new property list item at end with properties {kind:string, name:currentBSC, value:currentBSC}
         end if
      end tell
      --end try
   end tell
   
   
   
   set progress additional description to "Updating..."
   set progress completed steps to 4
   ------------------------------------------------------------------------------------------------
   --Set Batch Renaming Settings and run "Batch Rename" command
   ------------------------------------------------------------------------------------------------
   tell application "Capture One 10"
      --input BSC into Batch Rename window
      tell batch rename settings of current document
         set method to text and tokens
         set job name to currentBSC & "_" & shootDateShort & studioLocation
         set token format to "/Job Name/2 Digit Counter/"
      end tell
      
      set theVariants to selected variants
      tell current document
         batch rename variants theVariants
      end tell
   end tell
   
   delay 0.2
   
   set progress additional description to "Updating..."
   set progress completed steps to 5
   ------------------------------------------------------------------------------------------------
   --Apply metadata to specified fields
   ------------------------------------------------------------------------------------------------
   tell application "Capture One 10"
      set selectedVariants to (get selected variants)
      tell current document
         if selectedVariants is {} then
            display notification "No images selected -  select one or more images"
         else
            repeat with |counter| from 1 to count of selectedVariants
               set thisVariant to item |counter| of selectedVariants
               set oldStource to get status source of thisVariant
               
               set contact creator of thisVariant to shootName
               set contact creator job title of thisVariant to shootDate
               set contact address of thisVariant to modelname
               set contact city of thisVariant to timeOfDay
               set contact state of thisVariant to baynumber
               set contact postal code of thisVariant to photographerName
               set contact country of thisVariant to businessunit
               
            end repeat
         end if
      end tell
   end tell
   
   
   set progress additional description to "Updating..."
   set progress completed steps to 6
   
   -- Reset the progress information
   set progress total steps to 0
   set progress completed steps to 0
   set progress description to ""
   set progress additional description to ""
   


------------------------------------------------------------------------------------------------
--Array split
------------------------------------------------------------------------------------------------

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
SeanMurp
 
Posts: 38
Joined: Wed Nov 02, 2016 4:30 am

Re: Repeat with applying metadata sometimes doesn't apply

Postby SeanMurp » Thu Aug 03, 2017 7:28 pm

We found our issue. There were two places where we were getting selected variants. So, if the files were batch renamed and then the selection changed we were pulling a different set of selected variants.
SeanMurp
 
Posts: 38
Joined: Wed Nov 02, 2016 4:30 am


Return to Scripting



Who is online

Users browsing this forum: No registered users and 2 guests