Batch Rename Settings
Anyone have any luck with setting Batch Rename Settings? My initial playing around doesn't result any changes.
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.
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.
0
-
I have figured out how to get one Batch Rename Setting to take but still none of the others.
This one works properly:
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:
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.0 -
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.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. 🤭0 -
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. 0 -
Hi SeamMurp,
Odd. Can you provide your code?0 -
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. 0 -
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.0 -
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. 0 -
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.0 -
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: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.0 -
how would you batch rename the current collection instead of the current selection? 0 -
Anyone managed a batch rename of a collection of selected variants? 0 -
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.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 tell0 -
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".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.0 -
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:
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:
set theVariants to variants whose selected is true
instead of:
set theVariants to selected variants
Something about there being some bug with "selected variants". Hope some of this helps.0 -
Hi SeanMurp
Thanks for taking the time to support the resolution of my renaming issue. In this case I can exclude a focus change with certainty.
Also, it doesn't make any difference whether I useset theVariants to variants whose selected is true
instead ofset theVariants to selected variants
The problem must be related to the repeated and rapid invocation ofbatch rename variants
while renaming just a single variant each time.
My hypothesis is that Capture One updates (i.e. reorders) the image selection after each invocation (which is a very sensible thing to do!) and that — for whatever reason — this affects the list of variants used byrepeat with variant_ in selectedVariants
even though I (try) to create a copy of the original result ofselected variants
to avoid exactly this negative effect.0 -
Hi QBus,
Here is an idea that could get you out of repeating through individual files to name. Instead you could repeat through the selected files to set the image's original file number to a different IPTC field (similar to how you are setting the original file name to Status Source). Status Provider is the field directly above Status Source. Then do an actual batch rename on the selected variants but this time use the tokens to call Provider for the original file number. This also removes the adjustment of rename settings with each file (especially removing counter adjustment).
Below is a bit of re-working of your code that seems to work for me. Main changes:
1. numberSuffixFormat changed to Provider token
2. Only creating one list of selectedVariants
3. Repeat through selectedVariants to get the originalFileNameNumberSuffix and place that number in status provider metadata field (NOTE: I couldn't get your numberSuffix handler to compile. Kept giving me an 'Expected “,†but found “textâ€.' error).
4. Batch rename settings set once
5. Batch rename all selectedVariants at once.
Hope this works for you.
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 "[Provider]" -- 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
set selectedVariants to variants whose selected is true
--
-- Repeat to get file name number suffix and apply to metadata field
--
repeat with variant_ in selectedVariants
set i to parent image of variant_
set originalFileName to (name of i)
try
set originalFileNameNumberSuffix to my numberSuffix(originalFileName)
-- store originalFileName in "IPTC Status Source" field if field is still empty:
-- add number suffix to "IPTC Provider" field as text
tell variant_
if (status source = "") then
set status source to originalFileName
end if
set status provider to originalFileNameNumberSuffix
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
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 selectedVariants
end tell
display dialog "" & (count of selectedVariants) & " of " & numberOfFilesRenamed & " images renamed" buttons {"OK"}
end tell
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 numberSuffix0 -
I think I see a possible pitfall here.
When Capture one returns a list of variants, or a single variant, the variant is identified by its sequence number in the browser.
The sequence number of a given variant depends on the sort order of the browser, which may be Name, Date, Rating, Color Tag and a bunch of other fields.
For example here are two results for the same 3 selected images:
tell application "Capture One 11" to get selected variants
## images sorted by image name returns:
## {variant 5 of collection 7 of collection 1 of collection 4 of collection 8 of document "Main5M" of application "Capture One 11", variant 6 of collection 7 of collection 1 of collection 4 of collection 8 of document "Main5M" of application "Capture One 11", variant 7 of collection 7 of collection 1 of collection 4 of collection 8 of document "Main5M" of application "Capture One 11"}
tell application "Capture One 11" to get selected variants
## images sorted by image file size returns:
## {variant 177 of collection 7 of collection 1 of collection 4 of collection 8 of document "Main5M" of application "Capture One 11", variant 221 of collection 7 of collection 1 of collection 4 of collection 8 of document "Main5M" of application "Capture One 11", variant 232 of collection 7 of collection 1 of collection 4 of collection 8 of document "Main5M" of application "Capture One 11"}
So how does this apply to image renaming?
If the browser is set to order variants by parent image name, each renaming operation can change the index of one or many variants. The variant references now point to a different variant.
The first operation will be predictable, but the variant parent image renamed by the second operation could be as expected if the first variant remains before the second variant in the sort order, or rather unexpected if the renaming operation places the first variant after the second variant.0 -
Yes Eric, that is a good thing to point out when scripting the renaming of files. If you are renaming a set of files and then need to act further on those selected files after the rename you will need to set your variable to selected variants again. set selectedVariants to variants whose selected is true
This shouldn't be an issue with QBus's problem since they are interacting with values pulled from each individual file, so order of images should be independent of this process and not have an impact on the rename. But, yes, if the script was to then take further action on these images they would need to set the selectedVariants variable again.0 -
Hi Sean, hi Eric
Sean, your solution is is what I call looking at a problem from a different angle! Thank you very much for this creative solution. It works really nicely.
The reason you got that syntax error for find text is that I am using a rather nice library for regex matching that I had forgot to mention in the header of my script (it's mentionend now): http://www.satimage.fr/software/en/down ... saxen.html
Eric, I found exactly the same explanation for how variants are represented in Applescript: not much more than a position index to the current collection of Capture One. The index is only valid as long as the sort order of the collection remains unchanged, after that it may point to a wrong variant.
It took me some time to come up with a combination of two solutions to alleviate the problem with the fragile position index of Applescript variants:
1. From the current selection of variants, I create a list with just the names of those variants (this list will not change even if the names in Capture One do). Then I iterate over the names list, obtain the proper variant for each name and rename that variant.
2. I call refresh after each batch renaming invocation.
Now, my script looks like this and works like a charm:--
-- Renames a list of selected image variants honouring the original camera file-name number suffix
--
-- e.g. "DSC00044.jpg" to "OR_2018-02-15_00044.jpg"
--
-- something that Capture One seems unable to do.
--
-- 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 so:
--
-- "DSC00044.jpg"
--
-- This can later (and after possible further renamings) be used to revert back to the original file name or to
-- reuse the number suffix.
--
-- Note: This script uses the Satimage osax library for regex pattern matching and won't work without it
-- (see http://www.satimage.fr/software/en/down ... saxen.html)
--
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
set selectedVariants to variants whose selected is true -- assignment required to have correct type
if (count of selectedVariants) = 0 then
display dialog "No selection." buttons {"Abort"}
return
end if
--
-- Important: the Applescript representation of Capture One variants seems to be a rather poor concept
-- in that it is not much more than a numeric position index in a list rather than a proper, stable data
-- object for a given image (or variant, to be precise). This shortcoming becomes apparent when the
-- ordering of the list changes, e.g. if the list represents an image collection of Capture One and the
-- order of images in the collection is changeing due to ongoing renaming, then a given Applescript
-- variant can suddenly "point" to an object that wasn't even selected in the first place. As a consequence,
-- the wrong object may be processed.
-- Thus, in order to obtain a stable list of selected images, we create a list with just the *names* of the
-- variants in the current selection. Later, we iterate over those names later rather than over the "variants"
-- that are currently selected in Capture One.
--
set variantNames to {}
repeat with v in selectedVariants
set the end of variantNames to (name of 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
--
set numberOfFilesRenamed to 0
repeat with variantName_ in variantNames
set singleVariantList to (variants whose name is variantName_)
if ((count of singleVariantList) ≠1) then
display dialog "Error, found " & (count of singleVariantList) & " variant(s) named '" & variantName_ & "'." buttons {"Abort"}
end if
set variant_ to (item 1 of singleVariantList)
set originalFileName to (name of (parent image of variant_))
--display dialog "Original image name: " & originalFileName & ", variant name: " & (name of variant_) buttons {"OK"}
try
set originalFileNameNumberSuffix to my numberSuffix(originalFileName)
--display dialog "Original image name: " & (name of variant_) & ", 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
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
end tell
set numberOfFilesRenamed to numberOfFilesRenamed + 1
refresh -- this is crucial, otherwise the next listing of "variants" will return an incoherent result as outlined above
on error
display dialog "Error on image name: " & (name of variant_) 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 numberSuffix0 -
Hi Qbus
Good progress
Nice Library you reference, thanks!!
Two comments -
1)If you put your AppleScript code between [code] and [/code] (making sure to not select "Disable BBCode" below the editor window) then it becomes much more readable. These character sequences can be generated with the “code†button at the top of the editor.
2) The variant's ID is unique, unlike the name.You can write “get id of variants†and “get the variant whose id is theID†similar to the name (but more robust)0 -
Hi Eric
You truly made my evening! Sorry for not replying earlier but I kind of have to "steal" my time to work on this.
The name-based version of my script turned out to be usable when there were multiple variants of a picture and thus your hint number 2) solved this problem within a few minutes. Thank you very much for this!
Regarding 1): absolutely true. I did use the code tags earlier and I must just have hit the wrong button.
So, here is again the (hopefully) final version of my script for others to use:--
-- Renames a list of selected image variants honouring the original camera file-name number suffix
--
-- e.g. "DSC00044.jpg" to "AK_2018-02-15_00044.jpg"
--
-- something that Capture One seems unable to do.
--
-- 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 so:
--
-- "DSC00044.jpg"
--
-- This can later (and after possible further renamings) be used to revert back to the original file name or to
-- reuse the number suffix.
--
-- Note: This script uses the Satimage osax library for regex pattern matching and won't work without it
-- (see http://www.satimage.fr/software/en/downloads/downloads_companion_osaxen.html)
--
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
set selectedVariants to variants whose selected is true -- assignment required to have correct type
if (count of selectedVariants) = 0 then
display dialog "No selection." buttons {"Abort"}
return
end if
--
-- Important: the Applescript representation of Capture One variants seems to be a rather poor concept
-- in that it is not much more than a numeric position index in a list rather than a proper, stable data
-- object for a given image (or variant, to be precise). This shortcoming becomes apparent when the
-- ordering of the list changes, e.g. if the list represents an image collection of Capture One and the
-- order of images in the collection is changeing due to ongoing renaming, then a given Applescript
-- variant can suddenly "point" to an object that wasn't even selected in the first place. As a consequence,
-- the wrong object may be processed.
-- Thus, in order to obtain a stable list of selected images, we create a list with just the *is* of the
-- variants in the current selection (all variants of an image share the same name, so don't
-- use that. Later, we iterate over those ids later rather than over the "variants" that are currently
-- selected in Capture One (thanks to Eric Nepaean for this hint).
--
set variantIDs to {}
repeat with v in selectedVariants
set the end of variantIDs to (id of 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
--
set numberOfFilesRenamed to 0
repeat with variantID_ in variantIDs
set singleVariantList to (variants whose id is variantID_)
if ((count of singleVariantList) ≠1) then
display dialog "Error, found " & (count of singleVariantList) & " variant(s) named '" & variantID_ & "'." buttons {"Abort"}
end if
set variant_ to (item 1 of singleVariantList)
set originalFileName to (name of (parent image of variant_))
--display dialog "Original image name: " & originalFileName & ", variant name: " & (name of variant_) buttons {"OK"}
try
set originalFileNameNumberSuffix to my numberSuffix(originalFileName)
--display dialog "Original image name: " & (name of variant_) & ", 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
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
end tell
set numberOfFilesRenamed to numberOfFilesRenamed + 1
refresh -- this is crucial, otherwise the next listing of "variants" will return an incoherent result as outlined above
on error
display dialog "Error on image name: " & (name of variant_) 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 numberSuffix0
Please sign in to leave a comment.
Comments
21 comments