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 create a project / album / smart album structure

Comments

11 comments

  • Eric Valk

    *** This post is editted on 2021-03-08 to handle the missing backslash symbols  caused by the migration tool from the PhaseOne forum to the CaptureOne forum. See this post for a full explanation***

    I decided that I wanted a script like this too. Here it is; instructions are at the top.

    Because AppleScript cannot directly access the the "Recent Imports" folder, the user must select the desired folder, and optionally select the images to be imported.

    The script will import images from any collection the user selects.

    *** 2021-03-08 DO NOT USE THIS VERSION OF THE SCRIPT

    Instead, use the  script in my post below

    ## Version 1
    ## The user must start by selecting the collection to import from
    ## If no variants are selected, then all the variants in the collection are imported
    ## if the collection is empty (e.g. by selecting Recent Imports, instead of one of the subcollections) then no variants are imported
    ## A new Project is created, there is a dialog for the user to enter the name
    ## Inside the Project are an Album "All" and several Smart Albums

    tell application "Capture One 11" to set countVariants to count of selected variants
    if (countVariants > 0) then
    set isSelection to true
    set hasVariants to true
    tell application "Capture One 11" to tell current document to set nameCurrentCollection to name of current collection
    set SelectionDescription to (countVariants as text) & " Selected Variants in "" & nameCurrentCollection & """
    else
    tell application "Capture One 11" to set countVariants to count of every variant
    set isSelection to false
    if countVariants > 0 then
    set hasVariants to true
    tell application "Capture One 11" to tell current document to set nameCurrentCollection to name of current collection
    set SelectionDescription to (countVariants as text) & " Variants in "" & nameCurrentCollection & """
    else
    set hasVariants to false
    set nameCurrentCollection to "NotFound"
    set SelectionDescription to "No Variants"
    end if
    end if


    set getShootNameSuccess to false
    set ExplanationText to ""
    repeat while not getShootNameSuccess
    try
    set dialogMessage to ExplanationText & " Enter Name of the Shoot (Importing " & SelectionDescription & ")"
    set theShootName to text returned of (display dialog dialogMessage default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue")
    on error errorMessage number errorNumber
    if errorNumber ≠ -128 then
    error ("Script Error: " & errorMessage & " #" & errorNumber & " during Name of Shoot Entry")
    else
    error ("User Cancelled the Script at Name of Shoot Entry")
    end if
    end try

    tell application "Capture One 11" to tell current document to set ShootNameList to every collection whose name is theShootName
    if 0 = (count of ShootNameList) then
    set getShootNameSuccess to true
    else
    set ExplanationText to "A collection named "" & theShootName & "" already exists! Try again. "
    end if
    end repeat

    set saNoRules to "<?xml version="1.0" encoding="UTF-8"?><MatchOperator Kind="AND"></MatchOperator>"
    set saRedTagRules to "<?xml version="1.0" encoding="UTF-8"?><MatchOperator Kind="AND"><MatchOperator Kind="AND"><Condition Enabled="YES"><Key>IB_S_BASIC_URGENCY</Key><Operator>0</Operator><Criterion>1</Criterion></Condition></MatchOperator></MatchOperator>"
    set saGreenTagRules to "<?xml version="1.0" encoding="UTF-8"?><MatchOperator Kind="AND"><MatchOperator Kind="AND"><Condition Enabled="YES"><Key>IB_S_BASIC_URGENCY</Key><Operator>0</Operator><Criterion>4</Criterion></Condition></MatchOperator></MatchOperator>"
    set saNoColorTagRules to "<?xml version="1.0" encoding="UTF-8"?><MatchOperator Kind="AND"><MatchOperator Kind="AND"><Condition Enabled="YES"><Key>IB_S_BASIC_URGENCY</Key><Operator>0</Operator><Criterion>0</Criterion></Condition></MatchOperator></MatchOperator>"

    tell application "Capture One 11"
    tell current document
    set theNewProject to make new collection with properties {kind:project, name:theShootName}
    set theAllAlbum to make new collection at theNewProject with properties {kind:album, name:"All"}
    set theNoColorTagAlbum to make new collection at theNewProject with properties {kind:smart album, name:"NoColorTag", rules:saNoColorTagRules}
    set theRedTagAlbum to make new collection at theNewProject with properties {kind:smart album, name:"RedTag", rules:saRedTagRules}
    set theGreenTagAlbum to make new collection at theNewProject with properties {kind:smart album, name:"GreenTag", rules:saGreenTagRules}
    log (get name of current collection)
    end tell
    if hasVariants then
    if isSelection then
    add inside theAllAlbum variants selected variants
    else
    add inside theAllAlbum variants every variant
    end if
    end if
    end tell

    0
  • WPNL
    Maybe you can create a session with all smart folders and such, delete all photos and then copy this session folder as a template each following session?
    0
  • Jim_DK
    I could proffer a plan b:

    If you were to automate the collection creation, select the "all" album, then run import you can have the import reference the result in "selected album", negating the need to move them after import.

    Might be a different approach to your current workflow of having images in the catalog first, but it circumvents the issue of moving them after import from Recents.
    0
  • Eric Valk
    [quote="WPNL" wrote:
    Maybe you can create a session with all smart folders and such, delete all photos and then copy this session folder as a template each following session?

    Kevin is asking support for setting up 3 smart albums, an album and a project. This copying idea here won't help him much because in a session because you can't copy in smart albums - you can make a session template with smart albums, but you can only use it when creating the session.

    In any case the Kevin wants something to support his existing catalog workflow, switching to sessions will actually change his workflow considerably.

    You can, as some else has mentioned in another forum, create a template catalog with the right set set of proejects, albums and smart albums, and import this into the working catalog, and this may be easier for those wishing to avoid AppleScript.

    However the Applescript above creates all the smart albums and other collections and imports the images in one operation, so it is less trouble if you don't mind running an Applescript.
    0
  • Jeremy Henderson
    [quote="Eric Nepean" wrote:
    I decided that I wanted a script like this too.

    ...

    set saRedTagRules to "<?xml version="1.0" encoding="UTF-8"?><MatchOperator Kind="AND"><MatchOperator Kind="AND"><Condition Enabled="YES"><Key>IB_S_BASIC_URGENCY</Key><Operator>0</Operator><Criterion>1</Criterion></Condition></MatchOperator></MatchOperator>"


    Thanks Eric - you saved my life.

    May I ask how you knew to use the (bizarre) string "IB_S_BASIC_URGENCY" ??

    Thanks!!
    0
  • Eric Valk

    *** This post is editted on 2021-03-08 to replace the backslash symbols  that were deleted by the migration tool when the thread was migrated from the PhaseOne forum to the CaptureOne forum

    [quote="NN13765" wrote:
    [quote="Eric Nepean" wrote:
    I decided that I wanted a script like this too.

    ...

    set saRedTagRules to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><MatchOperator Kind=\"AND\"><MatchOperator Kind=\"AND\"><Condition Enabled=\"YES\"><Key>IB_S_BASIC_URGENCY</Key><Operator>0</Operator><Criterion>1</Criterion></Condition></MatchOperator></MatchOperator>"


    Thanks Eric - you saved my life.

    May I ask how you knew to use the (bizarre) string "IB_S_BASIC_URGENCY" ??

    Thanks!!



    I started by making a smart album with no rules, and extracted the rules string.
    The I added a color tag rule, and extracted the rules string
    Then I changed that to a rating rule, and extracted the rules string
    Then I added both rules with an AND, and extracted the rules string

    From that I had 6 or 8 rule strings for which I knew the purpose.
    I matched segments find common parts.
    I broke the strings up into parts, and then the syntax became obvious.

    If I need to write a new rule for which I don't know the syntax, I make a Smart Album with that rule, and then use Applescript to read the rule string, and then use Text Edit to break it into pieces that I recognise.

    Every rule starts with <?xml version=\"1.0\" encoding=\"UTF-8\"?>

    The rule groups are inserted between <MatchOperator Kind=\"AND\"> and </MatchOperator>

    Notice that every MatchOperator Kind= operator starts a group of rules and the group is ended by /MatchOperator

    0
  • Jeremy Henderson
    Brilliant - thanks - so much to learn !!
    0
  • Laurence Gibson

    I was trying to use your properties for a script to make a smart album. but script debugger keeps on throwing up a -2741 error due to the quotes inside the XML quote i.e. "1.0" and "UTF-8" is there something i am missing in using such xml snippets? 

     

    set saRedTagRules to "<?xml version="1.0" encoding="UTF-8"?><MatchOperator Kind="AND"><MatchOperator Kind="AND"><Condition Enabled="YES"><Key>IB_S_BASIC_URGENCY</Key><Operator>0</Operator><Criterion>1</Criterion></Condition></MatchOperator></MatchOperator>"

    0
  • Eric Valk

    OK, I see what has happend here. It's an error in the script generated by the SW used to move postings from the old "phaseone" forum to this "captureone" forum

    Most computer languages are challenged by the situation when one wants to include a symbol which has special meaning to the compiler inside a string of text.

    In this case the symbol  is used as the text delimiter (indicates the beginning and end of a string of text ) but is also included in the text.

    The solution used by Applescript and many other languages is to precede a special symbol which is intended as text with an escape character, in Applescript the symbol:  \  (backslash)

    The symbol " tells the Applescript compiler: this is the beginning or end of a string, EXCEPT when immediately preceded by the backslash symbol \    , then it's just a character

    In my script (just found it on my Mac), and certainly in my original posting, every  "   symbol inside the text string is preceded by a  \   as in this example line.

    set saNoRules to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><MatchOperator Kind=\"AND\"></MatchOperator>"

    But in the (copy of) my post with the script, all the occurrences of  \"  are replaced with just  "

    Why? This interpretation and use of the backslash symbol \ is common to many computer languages and compilers, and it seems the application that  migrated the content from the old website to the new website interpreted the symbol \ (backslash) in the classic way, not as as a character, and so all the \" sequences were changed to just

    Not just in my original post, but also in every reply.  nothing like a little consistency  LOL.

    I'll follow up this post with a reposting of my original script.

    0
  • Eric Valk

    Original script reposted, but not retested

    ## The user must start by slecting the collection to import from
    ## If no variants are selected, then all the variants are imported
    ## if the collection is empty (e.g. by selecting Recent Imports, instead of one of the subcollections) then no variants are imported
    ## A new Project is created, there is a dialog for the user to enter the name
    ## Inside the Project are an Album "All" and several Smart Albums

    tell application "Capture One 11" to set countVariants to count of selected variants
    if (countVariants > 0) then
    set isSelection to true
    set hasVariants to true
    tell application "Capture One 11" to tell current document to set nameCurrentCollection to name of current collection
    set SelectionDescription to (countVariants as text) & " Selected Variants in \"" & nameCurrentCollection & "\""
    else
    tell application "Capture One 11" to set countVariants to count of every variant
    set isSelection to false
    if countVariants > 0 then
    set hasVariants to true
    tell application "Capture One 11" to tell current document to set nameCurrentCollection to name of current collection
    set SelectionDescription to (countVariants as text) & " Variants in \"" & nameCurrentCollection & "\""
    else
    set hasVariants to false
    set nameCurrentCollection to "NotFound"
    set SelectionDescription to "No Variants"
    end if
    end if


    set getShootNameSuccess to false
    set ExplanationText to ""
    repeat while not getShootNameSuccess
    try
    set dialogMessage to ExplanationText & " Enter Name of the Shoot (Importing " & SelectionDescription & ")"
    set theShootName to text returned of (display dialog dialogMessage default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue")
    on error errorMessage number errorNumber
    if errorNumber ≠ -128 then
    error ("Script Error: " & errorMessage & " #" & errorNumber & " during Name of Shoot Entry")
    else
    error ("User Cancelled the Script at Name of Shoot Entry")
    end if
    end try

    tell application "Capture One 11" to tell current document to set ShootNameList to every collection whose name is theShootName
    if 0 = (count of ShootNameList) then
    set getShootNameSuccess to true
    else
    set ExplanationText to "A collection named \"" & theShootName & "\" already exists! Try again. "
    end if
    end repeat

    set saNoRules to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><MatchOperator Kind=\"AND\"></MatchOperator>"
    set saRedTagRules to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><MatchOperator Kind=\"AND\"><MatchOperator Kind=\"AND\"><Condition Enabled=\"YES\"><Key>IB_S_BASIC_URGENCY</Key><Operator>0</Operator><Criterion>1</Criterion></Condition></MatchOperator></MatchOperator>"
    set saGreenTagRules to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><MatchOperator Kind=\"AND\"><MatchOperator Kind=\"AND\"><Condition Enabled=\"YES\"><Key>IB_S_BASIC_URGENCY</Key><Operator>0</Operator><Criterion>4</Criterion></Condition></MatchOperator></MatchOperator>"
    set saNoColorTagRules to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><MatchOperator Kind=\"AND\"><MatchOperator Kind=\"AND\"><Condition Enabled=\"YES\"><Key>IB_S_BASIC_URGENCY</Key><Operator>0</Operator><Criterion>0</Criterion></Condition></MatchOperator></MatchOperator>"

    tell application "Capture One 11"
    tell current document
    set theNewProject to make new collection with properties {kind:project, name:theShootName}
    set theAllAlbum to make new collection at theNewProject with properties {kind:album, name:"All"}
    set theNoColorTagAlbum to make new collection at theNewProject with properties {kind:smart album, name:"NoColorTag", rules:saNoColorTagRules}
    set theRedTagAlbum to make new collection at theNewProject with properties {kind:smart album, name:"RedTag", rules:saRedTagRules}
    set theGreenTagAlbum to make new collection at theNewProject with properties {kind:smart album, name:"GreenTag", rules:saGreenTagRules}
    log (get name of current collection)
    end tell
    if hasVariants then
    if isSelection then
    add inside theAllAlbum variants selected variants
    else
    add inside theAllAlbum variants every variant
    end if
    end if
    end tell


    0
  • Laurence Gibson

    Eric,

    thank you so much for your help that is brilliant, all working now, 

     

    many thanks 

     

    LG

    0

Please sign in to leave a comment.