Batch Rename Settings

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

Batch Rename Settings

Postby SeanMurp » Thu May 11, 2017 5:01 pm

Anyone have any luck with setting Batch Rename Settings? My initial playing around doesn't result any changes.

Code: Select all
tell application "Capture One 10"
   activate
   set method of batch rename settings of current document to text and tokens
   set token format of batch rename settings of current document to "Job Name|_|2 Digit Counter"
end tell


I thought I'd be able to set up a session with my preferred rename settings, but perhaps these settings need to be done individually each time a batch rename function is performed? And speaking of, what is the best way to perform a batch rename via AppleScript? Still pretty newb to AppleScript so have been able to figure out setting most settings but figuring out new functions is not a strong suit.
SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am

Re: Batch Rename Settings

Postby SeanMurp » Mon May 22, 2017 10:57 pm

I have figured out how to get one Batch Rename Setting to take but still none of the others.

This one works properly:
Code: Select all
tell application "Capture One 10"
   set job name of batch rename settings of current document to "Test_Name"
end tell


These don't change anything:
Code: Select all
tell application "Capture One 10"
   set token format of batch rename settings of current document to "Job Name/_/2 Digit Counter"
   set method of batch rename settings of current document to text and tokens
end tell


And I still have yet to get the Batch Rename function to work properly.
SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am

Re: Batch Rename Settings

Postby Ernesto J. » Fri Jun 02, 2017 9:43 pm

Dictionary looks like this, and tells you what each setting can accept, whether its text or number or true/false

batch rename settings n : Settings defining all aspects of the batch rename process.

properties
method (text and tokens/‌find and replace)
token format (text) : Text used for 'text and tokens' rename method.
job name (text) : Job name used for 'text and tokens' rename method.
counter (integer) : Counter used for 'text and tokens' rename method.
counter increment (integer) : Counter increment used for 'text and tokens' rename method.
find text (text) : Text to be found for 'find and replace' rename method.
replacement text (text) : Text to replace the found text for 'find and replace' rename method.
include file extension (boolean)
pair RAWs and JPGs (boolean)

After some poking, a working set up script looks like this. Note you only have to address the document once.

Code: Select all
tell application "Capture One 10"
   tell batch rename settings of current document
      set method to text and tokens
      set job name to "MyJob"
      set token format to "Job Name/-/3 Digit Counter"
      set counter to 1
      set pair RAWs and JPGs to true
      set include file extension to false
   end tell


I haven't figured out the apply part yet. :oops:
Ernesto J.
 
Posts: 11
Joined: Mon Jul 11, 2016 4:28 pm

Re: Batch Rename Settings

Postby SeanMurp » Tue Jun 06, 2017 8:58 pm

Thanks for the response Ernesto. I gave that code a try and was only successful in changing the Job Name. Unfortunately Token format still doesn't change from what was previously set.
SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am

Re: Batch Rename Settings

Postby Ernesto J. » Wed Jun 07, 2017 8:41 am

Hi SeamMurp,

Odd. Can you provide your code?
Ernesto J.
 
Posts: 11
Joined: Mon Jul 11, 2016 4:28 pm

Re: Batch Rename Settings

Postby SeanMurp » Thu Jun 08, 2017 4:50 am

I used your code. Only Job Name actually changes. To check, select a file and go to File > Batch Rename Images. Token format doesn't change.
SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am

Re: Batch Rename Settings

Postby Ernesto J. » Thu Jun 08, 2017 11:48 am

Hi SeanMurp

With some additional poking I got it to work and a batch rename occurs, however the UI is unaffected by the parameters issued in the batch settings class.

Seems like a bug. I will open a ticket.
Ernesto J.
 
Posts: 11
Joined: Mon Jul 11, 2016 4:28 pm

Re: Batch Rename Settings

Postby SeanMurp » Fri Jun 09, 2017 3:34 pm

Good to hear. What was your code for getting the batch rename to occur? That is one of my other problems I wasn't able to get to function.
SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am

Re: Batch Rename Settings

Postby Ernesto J. » Tue Jun 13, 2017 10:08 am

Code: Select all
tell application "Capture One 10"
   tell batch rename settings of current document
      set method to text and tokens
      set job name to "MyJob"
      set token format to "/Job Name/-/3 Digit Counter/"
      set counter to 1
      set pair RAWs and JPGs to true
      set include file extension to false
   end tell
   
   set theVariants to selected variants
   tell current document
      batch rename variants theVariants
   end tell
end tell


I also found the syntax for tokens is a bit inconsistent. Filed a ticket for that also.
Ernesto J.
 
Posts: 11
Joined: Mon Jul 11, 2016 4:28 pm

Re: Batch Rename Settings

Postby SeanMurp » Tue Jun 13, 2017 4:14 pm

Thanks a lot for sharing Ernesto! It works well and will be a nice change from the GUI calls I was making as a work-around. And looks like it did change the interface window for Batch Rename Images in my system with those changes.

And that is strange that the token format varies slightly. This is the format I'd used for capture name format:

Code: Select all
set capture name format of first item of documents to "Name/_/2 Digit Counter"


And probably the reason that it wasn't working for batch renaming. Thanks again.
SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am

Re: Batch Rename Settings

Postby Corey Riggle » Tue Mar 27, 2018 8:10 pm

how would you batch rename the current collection instead of the current selection?
Corey Riggle
NYC
Digital Capture Specialist
Corey Riggle
 
Posts: 74
Joined: Thu Feb 05, 2009 10:51 pm

Re: Batch Rename Settings

Postby rapdigital » Tue Apr 03, 2018 11:51 am

Anyone managed a batch rename of a collection of selected variants?
rapdigital
Certified Professional
Certified Professional
 
Posts: 167
Joined: Mon Feb 02, 2009 1:52 pm

Re: Batch Rename Settings

Postby Corey Riggle » Tue Apr 03, 2018 2:16 pm

this renames the selected files. Is that what you mean?
This one is for 11, change the brackets in the tokens to "/" for version 10.

Code: Select all
tell application "Capture One 11"
   tell batch rename settings of current document
      set method to text and tokens
      set job name to "f"
      set token format to "[Image Folder Name]_[Job Name][3 Digit Counter]"
      set counter to 1
      set pair RAWs and JPGs to true
      set include file extension to false
   end tell
   
   set theVariants to selected variants
   tell current document
      batch rename variants theVariants
   end tell
end tell
Corey Riggle
NYC
Digital Capture Specialist
Corey Riggle
 
Posts: 74
Joined: Thu Feb 05, 2009 10:51 pm

Re: Batch Rename Settings

Postby QBus » Tue Sep 25, 2018 10:08 pm

In Lightroom I used to name my photos according to the following pattern:
<initials>_yyyy-MM-dd_<original filename number suffix>, e.g. "AK_2018-09-25_00825"

Unfortunately, Capture One does not provide the original filename number suffix as a token when batch renaming. The following script renames the variants in the current selection according to the above pattern by extracting the number from the original file name, e.g. "DSC00044.jpg".

Code: Select all
tell application "Capture One 11"
   
   set prefix to "AK"
   set dateFormat to "[Image Year (yyyy)]-[Image Month (MM)]-[Image Day of Month (dd)]" -- use Capture One token names
   set numberSuffixFormat to "[5 Digit Counter]" -- use Capture One token names
   set tokenFormat to prefix & "_" & dateFormat & "_" & numberSuffixFormat
   
   if (count of selected variants) = 0 then
      display dialog "No selection." buttons {"Abort"}
      return
   end if
   
   set numberOfFilesRenamed to 0
   set NEWLINE to ASCII character 10
   
   --
   -- Important: create a copy of the current selection because the selection order will change as variants are being renamed
   -- (which creates problems because we are going to rename the images one by one rather than as a batch)
   --
   set tmpList to selected variants -- assignment required to have correct type
   set selectedVariants to {}
   repeat with v in tmpList
      set the end of selectedVariants to v
   end repeat
   
   --
   -- Now "batch"-rename the variants one by one by (= not batch) setting the 'counter' token to the correct value for the respective variant
   --
   repeat with variant_ in selectedVariants
      set i to parent image of variant_
      set originalFileName to (name of i)
      --display dialog "Original image name: " & originalFileName buttons {"OK"}
      
      try
         set originalFileNameNumberSuffix to my numberSuffix(originalFileName)
         --display dialog "Original image name: " & (name of i) & ", suffix: " & originalFileNameNumberSuffix buttons {"OK", "Abort"} default button "OK" cancel button "Abort"
         
         -- store originalFileName in "IPTC Status Source" field if field is still empty:   
         tell variant_
            if (status source = "") then
               set status source to originalFileName
            end if
         end tell
         
         set singleVariantList to {variant_} -- 'batch rename' requires list parameter
         tell current document
            tell batch rename settings
               set method to text and tokens
               set token format to tokenFormat
               set counter to originalFileNameNumberSuffix
               set pair RAWs and JPGs to true
               set include file extension to false
            end tell
            
            batch rename variants singleVariantList
            delay 0.1 -- this fixes the issue that, in a batch, roughly half of the files were left with their name unchanged
         end tell
         set numberOfFilesRenamed to numberOfFilesRenamed + 1
         
      on error
         --display dialog "Error on image name: " & (name of i) buttons {"OK", "Abort"} default button "OK" cancel button "Abort"
      end try
      
   end repeat
   display dialog "" & (count of selectedVariants) & " of " & numberOfFilesRenamed & " images renamed" buttons {"OK"}
end tell

--
-- Extract the number suffix of the given file name, e.g. 44 from "DSC00044.jpg"
--
--   fileName must include type suffix, e.g. ".jpg" or ".raw", etc.
--
--    returns integer >= 0 or throws an error
--
on numberSuffix(fileName)
   set matchedText to (find text "[0-9]+\\.[^\\.]+$" in fileName with regexp and string result)
   set matchedText to (find text "^[0-9]+" in matchedText with regexp and string result)
   return matchedText as number
end numberSuffix

In addition, if the variant IPTC data property "Status Source" property is undefined, it is set to the original file name created by the camera, like "DSC00044.jpg", before renaming the variant. This information can later (and after possible further renamings) be used to programmatically revert back to the original file name or to re-use the number suffix.

The above script isn't perfect: sometimes only half the images are renamed :-( but there is no status indication or exception I can use to detect this. Capture One batch rename simply doesn't work properly! Setting a delay between each individual image renaming command helps … sometimes.

If someone finds a fix for this problem, then please post here. Thanks.
QBus
 
Posts: 4
Joined: Wed Oct 12, 2016 8:57 am

Re: Batch Rename Settings

Postby SeanMurp » Tue Sep 25, 2018 10:57 pm

Hi,
We had issues with batch renaming and it turned out to be user error. Some of our photographers would run our renaming script and change focus or change the selection while the script was running. This would change the selected variants and only some would be renamed/moved.

This is the code we use for batch renaming:
Code: Select all
tell application "Capture One 11"
   --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
      
        tell current document
           batch rename variants theVariants
        end tell
end tell


Since discovering the user error we haven't had those renaming issues. We also added some code to our other scripts that won't let them run while the renamer is running.


One other suggestion, Phase One recommended that when setting selected variants that you should use this code:
Code: Select all
set theVariants to variants whose selected is true


instead of:
Code: Select all
set theVariants to selected variants


Something about there being some bug with "selected variants". Hope some of this helps.
SeanMurp
 
Posts: 71
Joined: Wed Nov 02, 2016 4:30 am

Next

Return to Scripting



Who is online

Users browsing this forum: No registered users and 1 guest