メインコンテンツへスキップ

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

Batch renaming- wildcards?

コメント

14件のコメント

  • cdc
    I'm not certain I follow, but would the 'find and replace' function of the batch renaming tool work for you?
    0
  • Jerry C
    Unfortunately, no. Find and replace only finds a specific character or characters. I want to replace sequential numbers that precede the image name.
    0
  • Eric Valk
    This could be done with an Applescript.

    If understand correctly, you want to keep the first 4 characters, which you expect to be "IMG_".

    After that you want to insert a counter, and then finally the rest of the original image name. For example if the counter were 654, then "IMG_MN234" becomes "IMG_654MN234".

    I'd actually encourage you to do it slightly differently, and replace "IMG_MN234" becomes "IMG_654_MN234", so that the counter can be identified by leading and trailing characters for future operations.

    This is trivial in Applescript.

    If you're interested, I'll write one.
    0
  • Jerry C
    Similar to that. I want to define the manually sorted sequence with a sequential numeric prefix that I can remove after I import the images into a new catalog. The first part is easy by adding a counter to the image name via the batch rename tool. When Capture One imports, it rearranges images in name order, which is why this bit of digital kabuki is needed. Once imported, I can change the sort order to manual, after which, I no longer need the numeric prefix. So then, I would like to find a way to batch remove all of the numeric prefixes. This part seems not to be possible.

    It is the same problem as renaming any of the first 3 number of characters no matter what they are to something like IMG.
    0
  • Eric Valk
    Yah, an Applescript can remove characters as well as add them.

    If you are going to add a counter, the best way is to start and end the counter sequence with unique characters, then its easy to identify the sequence with a script.

    For example if the the original image name was "IMG_MN234", and the modified name was "IMG_654$MN234" then the script action is basically this
    • For each Variant
      • Get the name of the parent image
      • Find the postion number of the "_"
      • If there is a "_" then
        • Find the position number of the "$"
        • If there is a "$" then
          • The new name is: all the Characters up to and including "_" + all the characters after "$"
          • Set the name of the parent image to the new name.

    This handles the case when an image has several variants
    0
  • Jerry C
    Thanks for the details. I presume this is able to be run within Capture One (for the referenced files to stay linked).
    0
  • Eric Valk
    Here is a quicky Applescript that does what I suggested in the my last post.

    To start with, open Capture One and select one image. Rename it so that the name includes an embeedded counter that starts with "_" and ends with "$", like this: IMG_654$MN234

    Then start Script Editor, open a blank script file, and copy and paste the code below.
    Compile the code using the icon with the little hammer symbol. That should work without errors.
    Now run the script using the icon with the black triangle. it should run without errors, and the name of your image should be changed.

    Now go back and make 2 or more images with the counter sequence in the name. Select them both, and check that the script functions.

    If this does what you want it to, then you've entered into the dark side. 😊 👿 Make a folder, perhaps in your Documents folder for Capture One Scripts. Save this script there, as a "script". From here, you can run the script using Script Editor, and it will work as long as Capture One is running.

    You can go one step further if you want.

    Using Finder, click "Go" in the menu bar, press the option key, and select LIbrary with your mouse.

    If there isn't a folder "Scripts" inside "Library",make one.
    If there isn't a folder "Capture One Scripts" inside "Scripts", make one.

    Using Script Editor, save your new script here, as an "Application"

    Using Capture One, click on "Scripts" in the Menu bar, theen select "Update Scripts Menu". Your new script should appear in the Scripts Menu, and you can run it from there, without using Script Editor.

    If you make any changes, you are much better to debug using Script Editor, with the modified script as a "Script". This is much easier to debug. Once you've got it right, only then save it as an Application.


    use AppleScript version "2.4"
    use scripting additions

    tell application "Capture One 12" to set theVariantList to variants whose selected is true
    repeat with thisVariant in theVariantList
    tell application "Capture One 12" to set {thisParentImage, thisImageName} to {it, name} of (parent image of thisVariant)
    set {ptr1, ptr2, namelength} to {0, 0, (get length of thisImageName)}
    repeat with textCtr from 1 to namelength
    if ptr1 = 0 then
    if "_" = (get text textCtr of thisImageName) then set ptr1 to textCtr -- found the start
    else if "$" = (get text textCtr of thisImageName) then -- found the end
    set ptr2 to textCtr
    exit repeat
    end if
    end repeat

    if ptr2 > 0 then
    set newImageName to ((text 1 thru ptr1 of thisImageName) & (text (ptr2 + 1) thru namelength of thisImageName))
    tell application "Capture One 12" to set thisParentImage's name to newImageName
    end if
    end repeat
    0
  • Jerry C
    Many thanks, Eric. Works like a charm. What do I need to change in the script to also delete the leading "_" ? It's probably obvious, but my knowledge of AppleScript is minimal.

    OK not to bother reading further unless you want to know why I brought up this issue:

    Why do I want to do this? It's a throwback to when file names had to be 8 digits) and eliminating the _ gives me 100k versus 10k unique image names after the IMG prefix. I also set the prefix in each of my cameras to a unique 3 characters for each camera so I immediately know which camera the image was taken with, in which order, and have no two names alike. Over the years I have had 4 camera bodies and this naming method is very handy.

    Comment: The counter issue would be irrelevant if Capture One preserved the manual sort order when you to import a catalog with manually sorted images into another catalog. As it is, manual sort order reverts to name sort order, just as it does if you drag manually sorted images from one album to another with manually sorted images.

    Jerry C
    0
  • Eric Valk
    Hi Jerry
    No need to justify - AppleScript is about customization.

    In about the 4th last line, change 1 thru ptr1 to
    1 thru (ptr1-1)
    0
  • Jerry C
    I need to add the counter as a prefix to the image name to a series of manually sorted images.

    Using your first script works to remove the counter added as a prefix, but leaves a leading _ character, that can be batch removed (rename _ to ""). This would work for me. It is a simple 2 part process.

    If I use your second script to remove the _123$ counter used as a prefix, I get the error, Can’t get text 1 thru 0 of "_123$IMG12345."

    Is there an easy way is to add a line to remove the leading _ to your original script.

    I really need to learn Apple Script.
    0
  • Eric Valk
    I hadn’t realized that “_†could be the first character. I’ll send a fix tonight.
    If you want learn a little AppleScript, if remember correctly the Help item has a link to the AppleScript language reference.

    What happening is that 4th last line makes the new name from all the characters before “_†and after “$â€.

    But when there are no characters before “_â€, the line asks for text 1 thru 0 which is wrong.

    So we need to put in a test to check if ptr1 (position of the “_â€) is 1, and if it is don’t try use the characters before it.
    0
  • SFA
    [quote="Eric Nepean" wrote:
    I hadn’t realized that “_†could be the first character. I’ll send a fix tonight.
    If you want learn a little AppleScript, if remember correctly the Help item has a link to the AppleScript language reference.

    What happening is that 4th last line makes the new name from all the characters before “_†and after “$â€.

    But when there are no characters before “_â€, the line ask for text -1 thru 0 which is wrong.

    So we need to put in a test to check if ptr1 (position of the “_â€) is 1, and if it is don’t try use the characters before it.


    Eric,

    Canon cameras (not so much the 1D series which have editable prefix options) tend to start file names with IMG if the cameras is set to sRGB internal colour space and _MG for Adobe RGB.

    I'm not sure if any other manufacturers do the same thing.

    Not really relevant if working with RAW files of course but it offers some potential for adding a little complexity or clarity depending on one's point of view!


    Grant
    0
  • Eric Valk
    Heree is an updated script with logic that should handle just about any name variation.

    The only thing that breaks it is if there is already an image in the same OSX folder with the new name.


    use AppleScript version "2.4"
    use scripting additions


    tell application "Capture One 12" to set theVariantList to variants whose selected is true
    repeat with thisVariant in theVariantList
    tell application "Capture One 12" to set {thisParentImage, thisImageName} to {it, name} of (parent image of thisVariant)
    set {ptr1, ptr2, namelength} to {0, 0, (get length of thisImageName)}
    repeat with textCtr from 1 to namelength
    if ptr1 = 0 then
    if "_" = (get text textCtr of thisImageName) then set ptr1 to textCtr
    else if "$" = (get text textCtr of thisImageName) then
    set ptr2 to textCtr
    exit repeat
    end if
    end repeat

    set newImageName to ""
    if (ptr2 > 0) then
    if ptr1 > 1 then set newImageName to newImageName & (text 1 thru (ptr1 - 1) of thisImageName)
    if ptr2 < namelength then set newImageName to newImageName & (text (ptr2 + 1) thru namelength of thisImageName)
    if 0 < (get length of newImageName) then tell application "Capture One 12" to set thisParentImage's name to newImageName
    end if
    end repeat
    0
  • Jerry C
    Works perfectly. Many thanks.

    My workflow makes it unlikely any two files would have the same name, so that should not be a problem.

    Also, if the counter is added as a prefix to _MG jpg files, the script also works to delete the counter, leaving _MG as it was.

    Jerry C
    0

投稿コメントは受け付けていません。