Why does one work and the other doesn't?
I'm puzzled. I think a one-line script would do what another forum user has requested.
- set the current layer of all selected variants to the background layer
One user asked for a script to set a color label for all untitled variants. Your one-line script works.
tell application "Capture One" to tell (every variant whose content headline is "") to set color tag to 5
I thought setting the current layer to background would be just as easy. This doesn't work.
tell application "Capture One" to tell (every variant whose selected is true) to set current layer to first layer
I wrote the normal multi-line script and this does work.
-- select image layer of selected variants
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Capture One"
set selVarList to selected variants
repeat with thisVariant in selVarList
tell thisVariant to set current layer to first layer
end repeat
end tell
Why does the single-line script not work?
-
In the case of the first one liner (setting the color tag) we are assigning the same numerical value to the property of a list of variants, each variant's property legitimately gets the same value.
In the case of setting the current layer of a list of variants, each layer of each variant is an object,; that object is identified like one of
- layer Background" of variant id "1089" of collection id "203" of collection ....
- layer 2 of variant id "1089" of collection id "203" of collection ....
Assigning the current layer of variant 1089 to be some layer of variant 1084 is problematic and some SW developer is going to handle that with an error message.
So when we (try) to do this as a one liner the length of the list of current layers has to match the length of the list of layers that are assigned to it, and the object ID's have to match item for item.
I tried this prototype code below, which meets these conditions. (its not a one liner yet, but could be massaged into one). It doesn't throw an error, but it also doesn't change the current layer. Selected variants whose current layers are not the background layer don't change their current layers.
For now, I think the only solution is your code using a repeat loop.
I think this is a bug, developers probably didn't think of verifying this.
if true then
tell application "Capture One 23" to tell (every variant whose selected is true)
set C to get current layer
set A to get first layer
set B to get second layer
set C to A
end tell
end if0 -
Thank you Eric for looking at this and for your detailed explanation.
0 -
Since first layer is a list try this:
tell application "Capture One" to tell (every variant whose selected is true) to set current layer to item 1 of (first layer)
0 -
It makes sense why this code below doesn't throw an error. You have only "read" the properties. You have not tried to set any of them.
if true then
tell application "Capture One 23" to tell (every variant whose selected is true)
set C to get current layer
set A to get first layer
set B to get second layer
set C to A
end tell
end if0 -
tell application "Capture One" to tell (every variant whose selected is true) to set current layer to item 1 of (first layer)
That worked! One issue is that it fails when NO variants are selected. In my script it addresses this by setting the variant list to all variants if no variants are selected. One could alternatively simply do nothing if no variants are selected.
-- select image (backgreound) layer of selected variants
use AppleScript version "2.4"
use scripting additions
tell application "Capture One"
set selVarList to get selected variants
if count of selVarList is 0 then set selVarList to all variants
repeat with thisVariant in selVarList
tell thisVariant to set current layer to first layer
end repeat
end tell0
Post is closed for comments.
Comments
5 comments