Get Started With AppleScript – Basics
An intro series to scripting Capture One, with Ben Liddle
Preamble
Years ago, in a warehouse in deep industrial Brooklyn, I was a digital technician on an e-commerce photo shoot struggling to stay awake. It was 3:30 in the afternoon on a crisp winter’s day, and the stylist was diligently stringing up the 80 billionth (by my estimate) crossbody’s strap of the day. The photographer was (probably) retouching his latest editorial job on his laptop in the corner. I was working with Capture One Pro 8 (iirc, maybe it was 7, honestly there wasn’t much difference for this workflow), and pulling up yet another go-by for styling reference. It was one of those shit days where you arrive on set at call time before sunrise and just know in your bones that you’re not leaving before sunset.
As an aside, if you’re reading this and you were on set that day, I don’t mean to offend. I look back fondly on those days, those mid-shoot conversations, the catering, but I think we can all agree that it wasn’t the most enthralling of experiences.
The actual “work” I was doing on that job was mostly completed in the setup day from the week earlier; after that, it was scan the barcode, create a new Capture folder, name the capture folder, reset the capture counter, set the camera to Live View, set up the proper go-by as an overlay, make sure the stylist can see the Live View, take test shots, check focus, color tag images, process, comp in Photoshop, hit Chronosync, rinse, repeat ad nauseum.
If you’ve worked e-commerce, you probably had a similar flow.
I did this for years and years to pay rent, in between the “fun” jobs that filled up my passport pages. I figured there had to be a better way; a way to be lazier, yet not fuck up. Just do less. Fast forward a few years, ~13 versions (Capture One 20-Capture One 7=Capture One 13, the math checks out, fight me), and there’s little from that day on set that can’t be automated. Well, afaik you can’t automate rigging a crossbody strap to match the 799,999,999,999 previous, but I digress. My heart goes out to you still, stylist.
Heads up!
I’ll be using Capture One 20, since it’s known to be the most scriptable of the Capture One versions. If you haven’t tried Capture One 20, you can get a trial at https://www.captureone.com/en.
If you’ve made it this far and are on Windows, I’m afraid I can’t help you achieve peak lazy. As of this writing, only Capture One on macOS (and OSX, if you’re feeling retro) can be automated via scripts.
Capture One can run .scpt files in AppleScript (aka AS), Javascript for Automation (aka JXA), and AppleScript-ObjC. Frankly, I’m most comfortable in AS, have fairly extensive experience with JXA, but little/none with AS-ObjC. There’s obviously syntactical differences between the three languages, and for the purpose of these articles, I’ll be dealing mostly with AS.
For the rest of this story, I’ll be doing a bit of beginner’s intro to AppleScript and Capture One. If you have experience with AS, I suggest checking out the next post in this series: Selecting Variants and Images
Hello, World
As an introduction, we’re going to write a basic Hello, World to illustrate running scripts in Capture One. There are many, many IDEs (Integrated Development Environment, basically software for writing code) out there. For AS specifically, I’ve used a few:
Script Editor: already bundled with macOS. Simple. I’d say use this to get your feet wet, and for the first few stories I’ll be screen-shotting from this.
Atom (https://atom.io/): Open source text editor that can do just about… anything? You’ll need a few extensions to get it to parse/compile/execute AS, but it’s pretty.
Script Debugger (https://latenightsw.com/): My preference. Extremely verbose and powerful. Not free though, still a bargain at any price if you end up creating any complex automations, especially if they involve multiple applications.
Open up your IDE and create a new script named hello world.scpt.
Here’s the code we’ll be adding. Note: comments in AS are denoted by starting with — . Comments are blocks of the code that aren’t actually run and are used to explain what’s going on.
1 2 3 4 5 |
use AppleScript version "2.4" -- Yosemite (10.10) or later use scripting additions -- These two lines are standard and tell our script to use specifically AS version 2.4 as well as include the 'scripting additions' library. display dialog "Hello world." -- Call the display dialog verb of the scripting additions library and give it the text "Hello world." |
Press cmd+k to compile the script. If it compiles correctly, you’ll get indentations, syntax-based highlighting, the whole works. If not, you’ve made an error.
Hit the Run button to run the script.
Congrats. That’s AppleScript 101. You can find more on the basics here:
Hello (name of document)
Let’s start working with Capture One directly to get the name of the document; your session or catalog database file:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
use AppleScript version "2.4" -- Yosemite (10.10) or later use scripting additions tell application "Capture One 20" -- Instruct the AS interpreter to look for an application bundle whose name is "Capture One 20". This is the top-level scripting object. The tell verb opens what's known as a tell block. There's many kinds of blocks: tell, if, repeat, try, etc. For every block that you open, you must close it with an end call so the AS can compile properly. tell current document -- The application class contains an element called current document, which refers to the document that is currently in focus on screen. If you didn't know you could have more than one document open at a time, do yourself a favor and forget that I ever mentioned that you could. The current document is a Document class. set doc_name to name -- The Document class has a property called name. This is the name of the session db file (.cosessiondb) or catalog file (.cocatalogdb). Name is a text value. Here, we're using the set verb to set a variable (arbitrarily called doc_name) to that text value. display dialog "Looks like you've got " & doc_name & " open. Cool." -- Using that same display dialog call as before, we're feeding it a string that includes the doc_name variable. I am combining (well, concatenating actually) the text "Looks like you've got " with the variable text using the & character. This tells the interpreter that there's more text coming after that " character. After we feed it doc_name, we tell it to keep going even further with another &, followed by the text " open. Cool." end tell -- closing the tell current document block end tell -- closing the tell application "Capture One 20" block |
It’s worth pointing out here that the above code has the display dialog verb within the tell current document block. Because it’s nested, the current document is the one calling the display dialog. Any further interaction with the current document is blocked until that dialog is cleared (one of the buttons is pressed). This code appears to result in the same actions, but since display dialog is outside of the tell application and current document blocks, it’s the OS that’s calling it:
1 2 3 4 5 6 7 8 9 |
use AppleScript version "2.4" -- Yosemite (10.10) or later use scripting additions tell application "Capture One 20.0.4" tell current document set doc_name to name end tell end tell display dialog "Looks like you've got " & doc_name & " open. Cool." |
Because we stored the document’s name in the variable doc_name, we can extract that data and use it anywhere we like!
That’s a good enough intro. In the next story, we’re diving into some more complex workflows.
Ben Liddle is a data manager in Colorado who automates the shit out of the first half of the work/life balance so the second half can be more fun.
Pingback: Get Started With AppleScript – Conditional Processing pt1 – SHOOT MACHINE