Script to toggle black & white for selected variants
I discovered recently that Capture One does not have a menu command for switching an image to and from black & white mode and, therefore, there's no way to assign a keyboard shortcut to that command. The only way to do this is through the user interface, which is clunky, and a pain to apply to multiple items (one has to enable Edit Selected and then find the Black & White tool and the Enable Black & White box and tick it, and then copy and apply the adjustment to the selected images — which is a lot of operations to just toggle in and out of black & white mode).
My solution is an AppleScript (sorry, Windows users) which I then place in the Capture One Scripts folder (go to Scripts > Open Scripts Folder). Since Capture One's keyboard shortcut editor does not allow me to assign a shortcut to a script in the Scripts menu, I use the macOS System Settings > Keyboard > Keyboard Shortcuts settings to assign a keyboard shortcut to the menu item corresponding to the script (in my case, the script is named Toggle Black & White, and I assign command-shift-M to it, which isn't used anywhere else in Capture One).
The script is given below. The use of references and indexing is equivalent to using pointers in C/C++ (or references in C++, for that matter), and speeds up processing enormously. An implementation using standard AppleScript syntax for accessing the adjustments took about 25 seconds to toggle the settings on 200 images; using references brings the time down to under 8 seconds. Using Capture One's Enable Black & White command takes about 3 seconds, not including all the UI fiddling to get to it. (2020 27" iMac, 3.8GHz i7, 16GB.)
One important difference is that the Capture One command is a single operation, and can be undone with the Undo (command-Z) command; each image toggled by the script counts as a separate operation, so Undo only undoes the last image toggled. Of course, to undo the script's operation, one simply has to run it again, because the script actually toggles the setting on each image: if an image (variant) was in colour, it will be set to black & white, and if it was black & white it will be set to colour. The Capture One command simply switches everything selected to black & white or colour, regardless of its original value.
Anyway, I thought it would be handy, so, after much ado, the script itself. Enjoy.
-mike
=====================================
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Capture One 23"
set variantList to variants whose selected is true
set numVariants to count of variantList
set varIndex to 1
repeat until varIndex > numVariants
(*
If an error occurs, just go on to the next one.
*)
try
set curVar to (a reference to (item varIndex of variantList))
set curAdj to (a reference to (adjustments of curVar))
(*
Get current black & white setting and invert it.
*)
set curBW to black and white of curAdj
set black and white of curAdj to not curBW
end try
set varIndex to varIndex + 1
end repeat
end tell
-
What is selected is always defined via the browser - I don't really follow the comment about the viewer, but I don't think you have any way of accessing what is currently viewed in the viewer via scripting - beyond assuming - e.g setting 1 up view/ and then the primary variant (again what is primary variant is defined in browser).
2 -
That's great work man, thanks a lot for sharing this!
1 -
Hi there
I just started diving into scripting for Capture One. Because I just cannot get myself to work with Apple Script I'll be working with JXA, and will share some code, mainly just for the fun of it, maybe it will interest some of you. The equivalent of the code above looks something like this in JXA:
app = Application("Capture One 22");
app.includeStandardAdditions = true;
vs = app.documents.images[0].variants.whose({_match: [ObjectSpecifier().selected, true]});
for (let v of vs()[0] ){v.adjustments.blackAndWhite = v.adjustments.blackAndWhite() == true ? "false" : "true";}You gotta admit it's a little more compact. Performance wise there is nothing meaningful I can say about it, I tested it with an image with a hand full of variants so I couldn't see a difference with the AS version.
As for the issue with the multiple undo/redo actions: I haven't found a way yet to sail around that one. Maybe I'll find something, I'll let you know.
Best wishes
Paula
1 -
I get the confusion now. What is selected is determined in the browser, but if you select multiple variants you can toggle through them in the viewer by clicking or by using the arrow keys. Technically they are all still selected though, but the highlighting may suggest otherwise. There is no way of retrieving which variant is 'selected' in the viewer, as far as I can tell.
1 -
It occurs to me that I need to modify this script so that it can tell whether the current view is the Viewer or the Browser, because as it stands, it toggles the B&W setting on all variants selected in the Browser, ignoring the current selection in the Viewer. So, a bit more work, but probably not too difficult. I may post the updated version here once I get it going if anyone is interested.
0 -
www.shootmachine.co: Yes, you're right. I was getting a bit confused with the highlighting of the current variant in the Viewer, but that's not the same as a selection, really. Anyway, it works as is. Cheers!
0 -
but that's not the same as a selection
Mike Conley how's that?
0 -
Paula Dieterman Where do you find the language reference for JXA, especially the CaptureOne JXA terminology?
0 -
Eric Valk Of course you won't find any on the C1 website. References, handbooks etc are quite sparse and/or old, like the official Apple release notes, but there are some good starting points, like this one: https://gist.github.com/JMichaelTX/d29adaa18088572ce6d4.
There are some good examples to be found here: https://jxa-examples.akjems.com/.
I found this one very helpful: https://bru6.de/jxa/, it will definitely help you avoiding some pitfalls when starting with jxa. If you work with Apple's script editor you can select the Capture One library and choose "JavaScript', just as you would with AppleScript. The terminology is the same and when you have found your way around the cliffs in JXA, it will feel familiar.
0 -
Walter Rowe I assume you mean the variant that is picked? That is nothing more than the variant that is promoted to the top spot of the variant list. You can look for a variant that is picked in a script, but that doesn't necessarily mean it is selected by the user. Whatever variant is selected in the viewer will be highlighted and synchronised with the browser.
0
Please sign in to leave a comment.
Comments
10 comments