Adding Smart Album

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

Adding Smart Album

Postby NNN635507854404933529 » Thu Mar 15, 2018 5:41 pm

Hi everyone,

I'm totally new in scripting. I've been looking everywhere on this forum and on the internet for this info and I'm sorry if the answer has already been published somewhere but I've been struggling for days 'cause I just can't find out how to script smart albums in COP10.
I've been trying so far coding as for albums replacing the kind "smart album" instead of "album" without luck :
Code: Select all
tell application "Capture One 10"
        activate
   tell document 1
      set myNewSmartAlbum to make new collection with properties {name:"Test", kind:smart album}
   end tell
end tell

returns error "Error in Capture One 10 : An error occurred while trying to make this collection." number -2710 from collection to class

And can somebody help me to figure out how to set the rules for smart albums ? Let's say I want a Smart Album with the preset "Color Tag is Red". Will the following line code work and be enough ?
Code: Select all
set color tag for myNewSmartAlbum to 1


Thank you very much for your help !
NNN635507854404933529
 
Posts: 2
Joined: Wed Nov 05, 2014 12:57 pm

Re: Adding Smart Album

Postby Eric Nepean » Fri Mar 16, 2018 1:25 am

I tried and got the same error. So I thought - perhaps its not possible to have a Smart Album without defining a rule.

I created a new Smart Album in the usual way with no rules, then used Applescript to read the rules:
Code: Select all
   log class of basicrules
   log (get rules of collection 5)
The results are:
    (*text*)
    (*<?xml version="1.0" encoding="UTF-8"?><MatchOperator Kind="AND"></MatchOperator>*)

Aha!! so the rules are a text string, and that is the text string for the default rules that do nothing. The following code segment works:
Code: Select all
   set newrules to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><MatchOperator Kind=\"AND\"></MatchOperator>"
   set theNewColl to make new collection with properties {kind:smart album, name:"Test 127", rules:newrules}
There ya go.
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 221
Joined: Sat Oct 25, 2014 8:02 am

Re: Adding Smart Album

Postby NNN635507854404933529 » Fri Mar 16, 2018 4:14 am

Oh brilliant ! You're a genius Eric !!
So to get it work I just had to set my rules as a string as you mentioned and, for instance, to set the filter "Color Tag is Red" the following code works :
Code: Select all
set newrules 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>"


Thank you very much Eric !!!
NNN635507854404933529
 
Posts: 2
Joined: Wed Nov 05, 2014 12:57 pm

Re: Adding Smart Album

Postby SeanMurp » Fri Apr 13, 2018 7:55 pm

Just a bit of our code as additional examples (includes deleting collections):

Code: Select all
tell application "Capture One 10"
   set theDoc to current document
   tell theDoc
      browse to path sessionNamePathPosix & "/Capture"
      delay 0.25
      tell application "System Events" to key code 97
      --------------------------------------------
      --Make Initial Selects Smart Album (images that have star rating of 1 or more)
      --------------------------------------------
      set myRulesInitial to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><MatchOperator Kind=\"AND\"><MatchOperator Kind=\"AND\"><Condition Enabled=\"YES\"><Key>IB_I_BASIC_RATING</Key><Operator>2</Operator><Criterion>1</Criterion></Condition></MatchOperator></MatchOperator>"

      make new collection with properties {kind:smart album, name:"Initial Selects", rules:myRulesInitial}
               
      --------------------------------------------
      --Make Final Selects Smart Album (images that have green label and rating of 1 or more)
      --------------------------------------------
      set myRulesFinal to "<?xml version=\"1.0\" encoding=\"UTF-8\"?><MatchOperator Kind=\"AND\"><MatchOperator Kind=\"OR\"><Condition Enabled=\"YES\"><Key>IB_S_BASIC_URGENCY</Key><Operator>0</Operator><Criterion>4</Criterion></Condition><Condition Enabled=\"YES\"><Key>IB_S_BASIC_URGENCY</Key><Operator>0</Operator><Criterion>5</Criterion></Condition></MatchOperator></MatchOperator>"

      make new collection with properties {kind:smart album, name:"Final Selects", rules:myRulesFinal}
               
      --------------------------------------------
      --Delete 'Five Stars' and 'All Images' Smart Albums
      --------------------------------------------
      tell theDoc
          if exists collection named "Five Stars" then
         delete collection named "Five Stars"
          end if
          if exists collection named "All Images" then
         delete collection named "All Images"
          end if
      end tell
   end tell
end tell
SeanMurp
 
Posts: 67
Joined: Wed Nov 02, 2016 4:30 am


Return to Scripting



Who is online

Users browsing this forum: No registered users and 1 guest