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. ⚠️

script to import Raw from a pair ?

Comments

7 comments

  • Hugues
    I tried a little with the C1 dictionary but I'm afraid this is not possible.
    There is an import command but it needs a "document type" argument. I can't figure any simple way to create a C1 document from the path of an image that is not already in the catalog
    0
  • Eric Valk
    In Capture One Applescript, Document does not refer to an image file, it refers to a session or to catalog file. Current Document is a property of the application which is a reference to the currently open and visible catalog or session.

    You can also refer to document 1

    This code works; you must first create an Album in the User Collection part of the Library, and select it. Then run the script. And then you will want to add the usual fault handling etc.

    set aFile to choose file with prompt "Choose a file"
    tell application "Capture One 12" to import (get current document) source aFile
    0
  • Hugues
    Thanks Eric.

    Would you know a way to access the file through its path ?

    The idea is to select a jpeg and automatically import the raw which is at the same location.
    So :
    1) get the path of the selected jpeg
    2) build the path to the associated raw
    3) create file object that is designated by path at 2)
    4) use your script

    the problem is at 3)
    all ideas I have tried failed
    0
  • Eric Valk
    Editted
    Hi Hugo
    Here is a script that takes the JPG variants that are selected and imports the corresponding RAW images. I have tested it for user collections; it should also work if the collection is "All Images" but I have not tested that part.

    First, set the extension for your Raw files ithe line
    set rawExtension to "RW2"

    Now select one or more variants. For each variant whose extension is "JPG", the raw file with the same name will be imported into Capture One, and put in the current user collection, or into All Images if the current collection is not a user collection.


    tell application "Capture One 12"
    set theDoc to get current document
    set theVariantList to variants whose selected is true
    tell theDoc
    set isUser to user of current collection
    tell its import settings
    ## If these things in the import recipe are not set correctly, the import results can be quite unpredictable
    copy its properties to b4ImportProps
    set {destination type, erase after copy, eject card} to {current location, false, false}
    if isUser then
    set destination collection to selected album
    else
    set destination collection to recent
    end if
    end tell
    end tell
    end tell

    set rawExtension to "RW2"

    if (0 < (get count of theVariantList)) then
    repeat with varCtr from 1 to count of theVariantList
    tell application "Capture One 12" to set theVarPath to path of (parent image of variant varCtr)
    if theVarPath contains "JPG" then
    set rawFilePath to replaceText(theVarPath, "JPG", rawExtension)
    tell application "Capture One 12" to import theDoc source rawFilePath
    end if
    end repeat
    end if

    ## Now restore the original Import settings
    tell application "Capture One 12" to tell theDoc to tell its import settings
    set {destination type, destination collection, erase after copy, eject card} to ¬
    {destination type, destination collection, erase after copy, eject card} of b4ImportProps
    end tell
    =======================

    on replaceText(this_text, search_string, replacement_string)
    set astid to AppleScript's text item delimiters
    try
    set AppleScript's text item delimiters to the search_string
    set the item_list to every text item of this_text
    set AppleScript's text item delimiters to the replacement_string
    set this_text to the item_list as string
    end try
    set AppleScript's text item delimiters to astid
    return this_text
    end replaceText
    I first worked with Apple's Script editor for about a year. As you likely know its a poor debugger, can be frustrating at times.
    Then I purchased Script Debugger, this offers a lot more insight if you open the Dictionary and use the Explorer function - this shows the current values of all the classes and properties of an application. There is a 30 day free trial, after wihich it becomes "Script Debuger Lite" if you do not purchase.
    0
  • Hugues
    Hi Eric

    Thanks to pointing me to Script Debugger.
    I've downloaded it and am impressed by the power of it. I'm not a computer engineer but I might buy it nevertheless, given how powerful it is.

    Thanks also for kindly providing me with this script. I really appreciate it.

    I've tried it but can't have it working, and I am limited to how I can repair it by my current knowledge of AS

    set isUser to user of current collection

    I have a bug here; likely because "user" is not a property collection.(*)
    I understand you are trying to test if the current collection is a user collection, in order to avoid putting the imported raw in unwanted places.
    From what I have guessed, I don't see any other way than testing against the name of the collection, which is quite cumbersome and different for any user (and need localisation).

    I set isUser to true to debug further

    (*) (Maybe Capture one 11 is different from Capture one 12 ?)

    tell application "Capture One 11" to set theVarPath to path of (parent image of variant varCtr)

    My understanding is that the code is referring to the variants in the collection, not in the selected variants.
    As a consequence, this imports the first picture in the album, not in the variantList, which is not what is intended.

    So we need to repeat on the variants in the variant list.
    This seems to work :

    if (0 < (get count of theVariantList)) then
    repeat with myVariant in theVariantList
    tell application "Capture One 11" to set theVarPath to path of (parent image of myVariant)
    if theVarPath contains "JPG" then
    set rawFilePath to replaceText(theVarPath, "JPG", rawExtension)
    tell application "Capture One 11" to import theDoc source rawFilePath
    end if
    end repeat
    end if


    This version performs ok and meet the objective of the post. I let you correct it and post it if you want to add additional points.

    Thanks again for your very useful input.
    0
  • Eric Valk
    Hi Hugo
    I didn't realise you were working with Capture One 11; yes the Applescript in Capture One 12 is considerably enhanced. For example the Collections User property did not exist until Capture One 12.

    I had been testing this using Capture One 12.03
    [quote="HugoinParis" wrote:
    Hi Eric
    .....
    set isUser to user of current collection
    I have a bug here; likely because "user" is not a property collection.(*)
    I understand you are trying to test if the current collection is a user collection, in order to avoid putting the imported raw in unwanted places.
    Exactly so in Capture One 11. But not in Capture One 12.

    From what I have guessed, I don't see any other way than testing against the name of the collection, which is quite cumbersome and different for any user (and need localisation).
    In Capture One 11 you can check that the collections kind is an album
    This is perhaps a better test than the one I had because only User Albums, All Images and Recents (both Smart Albums) can be used the import collection destination

    I set isUser to true to debug further
    And now you are aware of the limitation, the reason and the workaround

    ......
    tell application "Capture One 11" to set theVarPath to path of (parent image of variant varCtr)
    My understanding is that the code is referring to the variants in the collection, not in the selected variants.
    As a consequence, this imports the first picture in the album, not in the variantList, which is not what is intended.

    You are quite correct, and your correction is good.
    I did not catch my mistake because I had only three variants in my test catalog.
    [/quote]
    0
  • Hugues
    So here is the script for C1 11.

    [ I haven't implemented the "kind is an album" option as my understanding is that it would not work if the selected collection is in "recent imports". So the user needs to select a user collection first]


    -- This script imports the paired raw from a choosen jpeg

    tell application "Capture One 11"
    set theDoc to get current document
    set theVariantList to variants whose selected is true
    tell theDoc

    -- set isUser to user of current collection -- works only in capture 12
    -- Work-around. In C1 11, needs to be tested manually against being a user album
    set isUser to true

    tell its import settings
    ## If these things in the import recipe are not set correctly, the import results can be quite unpredictable
    copy its properties to b4ImportProps
    set {destination type, erase after copy, eject card} to {current location, false, false}
    if isUser then
    set destination collection to selected album
    else
    set destination collection to recent
    end if
    end tell
    end tell
    end tell

    set rawExtension to "CR2"

    if (0 < (get count of theVariantList)) then
    repeat with myVariant in theVariantList
    tell application "Capture One 11" to set theVarPath to path of (parent image of myVariant)
    if theVarPath contains "JPG" then
    set rawFilePath to replaceText(theVarPath, "JPG", rawExtension)
    tell application "Capture One 11" to import theDoc source rawFilePath
    end if
    end repeat
    end if

    ## Now restore the original Import settings
    tell application "Capture One 11" to tell theDoc to tell its import settings
    set {destination type, destination collection, erase after copy, eject card} to ¬
    {destination type, destination collection, erase after copy, eject card} of b4ImportProps
    end tell
    -----------------------

    on replaceText(this_text, search_string, replacement_string)
    set astid to AppleScript's text item delimiters
    try
    set AppleScript's text item delimiters to the search_string
    set the item_list to every text item of this_text
    set AppleScript's text item delimiters to the replacement_string
    set this_text to the item_list as string
    end try
    set AppleScript's text item delimiters to astid
    return this_text
    end replaceText
    0

Post is closed for comments.