Variants in Multiple Albums
This is an attempt to provide a solution to a request posed in the Mac forum recently regarding filtering albums by the contents' appearance in multiple albums. I.e. identify variants occurring in Album A and Album B. No such collection filter exists, I believe, but it seemed that the next best thing was to create yet another album with further copies of the repeated variants...
So here we are. The biggest hurdle I have faced in scripting CO is with the collection object: specifically its the lack of a parent property or equivalent. Or else I'm missing something very basic (quite possible). Could I have made the recursive handler simpler?
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
use framework "Foundation"
-- Show variants occurring in two or more nominated albums.
-- This script may create albums of existing variants inside one additional user project
-- but no further alterations to your catalogue.
property scriptTitle : "Images in Multiple Albums"
property reportProjectName : "In Multiple Albums"
global currentCollection
tell application "Capture One 20"
set currentDocument to current document
tell currentDocument
set currentCollection to current collection
if currentCollection is missing value or kind of currentCollection is not album then
display dialog "Please first select an album to compare against one or more others then re-run this script." buttons {"Cancel"} default button "Cancel" with title scriptTitle with icon 1
return
end if
-- Get list of albums for comparison
set albumPathsAndContents to my combCollections(currentDocument, missing value)
set allAlbumNames to item 1 of albumPathsAndContents
end tell
end tell
choose from list allAlbumNames with prompt "Select album(s) to scan for images also present in \"" & name of currentCollection & "\". Images present in every album will be added to a new album under the project named \"" & reportProjectName & "\"." with title scriptTitle with multiple selections allowed
set albumPath to result
if albumPath is false then
return
end if
set resultIndices to my indicesOf:albumPath inList:allAlbumNames
tell application "Capture One 20"
set compAlbums to {}
repeat with i in resultIndices
copy item i of item 2 of albumPathsAndContents to end of compAlbums
end repeat
-- Now all comparison albums are in the compAlbums list
set a1Variants to variants of currentCollection
set duplicatedVariants to {}
repeat with v in a1Variants
set vID to v's id
set vExists to true
tell currentDocument
repeat with compAlbum in compAlbums
set compIDs to id of variants of compAlbum
try
if compIDs does not contain vID then
--log "Variant " & vID & " not in " & name of compAlbum
set vExists to false
exit repeat
end if
on error errMsg number errNum
display dialog "Error " & errNum & ": " & errMsg buttons {"Cancel", "OK"} default button "OK"
end try
end repeat
if vExists then
copy v to end of duplicatedVariants
end if
end tell
end repeat
if (count of duplicatedVariants) > 0 then
set reportAlbum to my setUpDupAlbum(currentDocument, count of compAlbums)
if reportAlbum is not false then
tell currentCollection
add inside reportAlbum variants duplicatedVariants
end tell
end if
end if
end tell
on setUpDupAlbum(doc, compAlbumCount)
set pluralise to ""
if compAlbumCount > 1 then set pluralise to "s"
tell application "Capture One 20"
tell doc
try
set reportProject to some collection whose name is reportProjectName and kind is project
on error errMsg number errNum
if errNum is -1730 then -- empty list
tell doc
set reportProject to make new collection with properties {kind:project, name:reportProjectName}
end tell
else
display dialog "Error " & errNum & ": " & errMsg buttons {"Cancel", "OK"} default button "OK"
return false
end if
end try
set dupCounter to 1
-- example name for reporting album: "SJ Picks & 2 others 12/8/21: 1"
set dupResultAlbum to (name of currentCollection) & " & " & compAlbumCount & " other" & pluralise & " " & (short date string of (current date)) & ": "
repeat
tell application "Capture One 20"
tell reportProject
try
set reportAlbum to make new collection with properties {kind:album, name:(dupResultAlbum & dupCounter)}
exit repeat
on error errMsg number errNum
if errNum is -2710 then -- collection exists with this name
set dupCounter to dupCounter + 1
else
display dialog "Error " & errNum & ": " & errMsg buttons {"Cancel", "OK"} default button "OK"
return false
end if
end try
end tell
end tell
end repeat
return reportAlbum
end tell
end tell
end setUpDupAlbum
on indicesOf:inString inList:aList
set resultIndices to {}
repeat with s in inString
set anNSString to (current application's NSString's stringWithString:s)
set anNSArray to (current application's NSArray's arrayWithArray:aList)
set theIndex to (anNSArray's indexOfObject:anNSString) -- 0-based
copy (theIndex as integer) + 1 to end of resultIndices -- AS 1-based
end repeat
return resultIndices
end indicesOf:inList:
-- Return parallel lists of collections and their paths.
-- We need the paths because names of collections are insufficient id for user interaction.
on combCollections(theContainer, containerPath)
local theseGroups, someAlbums, theseAlbums, collectionID, thisAlbum
set pathList to {}
set collectionList to {}
tell application "Capture One 20"
tell theContainer
set theseGroups to its collections whose user is true and (kind is group or kind is project)
repeat with thisGroup in theseGroups
set groupName to name of thisGroup
if containerPath is not missing value then
set groupName to containerPath & "->" & groupName
end if
set pathsAndCollections to my combCollections(thisGroup, groupName)
set pathList to pathList & item 1 of pathsAndCollections
set collectionList to collectionList & item 2 of pathsAndCollections
end repeat
set branchAlbums to its collections whose kind is album
set albumPaths to {}
set theAlbums to {}
repeat with thisAlbum in branchAlbums
if contents of thisAlbum is not currentCollection then
if containerPath is missing value then
copy thisAlbum's name to end of albumPaths
else
copy containerPath & "->" & thisAlbum's name to end of albumPaths
end if
copy contents of thisAlbum to end of theAlbums
end if
end repeat
return {albumPaths & pathList, theAlbums & collectionList}
end tell
end tell
end combCollections
-
I have previously shared a script in this forum very similar to yours, and the metthods are similar.
One observation is that every group, album or project that contains the image also contains all of its variants. Because thre are more variants, t is simpler and faster to search for the image ID than the variant ID, and gives the same results.
My premise may be different than yours. I use fairly large catalogs; for my purposes a variant or image is lost if its not in a collection other than All Images. For me, duplication is expected. An Image of my brother on a canoe trip may fall into Projects for that Canoe trip, Canoe tripping, Family and Humour.
But then its is useful to know which projects and albums a particular image is in, and thus your script is useful for that purpose.
There are some interesting ideas in your script (I need to grok the indicesOf function) , I am going to copy your script and investigate further.
0
Post ist für Kommentare geschlossen.
Kommentare
1 Kommentar