Simple question

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

Simple question

Postby NN245802UL » Thu Aug 02, 2018 6:58 pm

How can I select an album with name "the name" an delete it.
So I need too to know how select an collection with a name and an kind
NN245802UL
 
Posts: 4
Joined: Thu Jul 29, 2010 12:02 pm

Re: Simple question

Postby Eric Nepean » Fri Aug 03, 2018 12:58 am

Capture One gets upset if you delete the collection which is the current collection. And the errorr message is actually incorrect and misleading.

On the other hand, collection 1 is "All Images" (which can never be deleted, and is always present).
One strategy is to select the album to be deleted, get the AppleScript reference to that collection, select any other collection (All Images is always there - so use that), and then delete the collection that was selected.

This code works. Select the collection which is to be deleted, and run the script.
Code: Select all
tell application "Capture One 11" to tell (get current document)
   set theOldCollection to get current collection
   set the current collection to collection 1
   delete theOldCollection
end tell

On the other hand if you want to delete some collection which you know the name of, there is no need to select it.
Assuming that the current Project or Group contains an album named "Untitled", this works
Code: Select all
tell application "Capture One 11" to tell (get current document) to tell (get current collection)
   delete collection "Untitled"
end tell

However, if the collection to be deleted is at the top level (not inside any Project or group) then this is needed:
Code: Select all
tell application "Capture One 11" to tell (get current document)
   delete collection "Untitled"
end tell

Filtering requires a little trick to work on Capture One collections. For example, the first and second lines work, the third does not:
Code: Select all
tell application "Capture One 11" to tell (get current document) to tell (get current collection)
   get collection "Untitled"
   get first collection whose name is "Untitled"
   get collection whose name is "Untitled" -- creates an error
end tell

It's a good idea to test your code with "get" before using "delete"
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 401
Joined: Sat Oct 25, 2014 8:02 am

Re: Simple question

Postby NN245802UL » Fri Aug 03, 2018 4:37 pm

Thanks a lot. Scripting is no easy to me. I have programming for a lots of years but allway in a structured languages.
I will try all yours pieces of source to understand this kind of programming.
Can You recommend me useful and interesting resources to learn scripting.
Above all I learn by seeing examples to do concrete things. From this I find rather little. Especially orienting it to Capture One
Again, thanks to get the time to answer me.
NN245802UL
 
Posts: 4
Joined: Thu Jul 29, 2010 12:02 pm

Re: Simple question

Postby Eric Nepean » Fri Aug 03, 2018 5:27 pm

Well, first of all, always check the AppleScript dictionary for Capture One carefully.

Script Editor has a useful link to the AppleScript language guide - from there - Index, click on a letter, find a command or topic.

The MacScripter forum has some of the smartest AppleScript brains on the planet. There is a forum, shared code and tutorials.

Some times I just use google search to find possible answers. Quite often find good answers in Stack Exchange.

Script Editor has poor debug features. So write-test-write-test in small pieces.

It’s very useful to check the “replies” section of the Script Editor log window. It shows the real reply from the application.

It’s easy to comment out one or two lines that shouldn’t run. But to put a larger section “on hold”, surround it with
Code: Select all
If false then
...............
end if


Check out my other postings, like the one on “Image Search” for lots of examples on interacting with CO.
Cheers, Eric
[late 2015 iMac, 4GHz i7, 24GB RAM, external SSDs. GX8, E-M1, GX7, GM5, GM1 ....]
Eric Nepean
 
Posts: 401
Joined: Sat Oct 25, 2014 8:02 am


Return to Scripting



Who is online

Users browsing this forum: No registered users and 2 guests