There seems to be a bug in the list of options for the “scaling method” property of “recipe”
I am able to set the value of “scaling method” to every option apart from “Height” and “Width” an error is generated if I try and Script Editor and Script Debugger don’t recognise them as part of the enum list of options for “scaling method”
Has anyone else come across this? Am I missing a workaround? Is this not a bug and I’m just being dumb?
Working with latest version of Capture.
Here is the simplified code I am using:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Capture One 20 2"
tell current document
tell recipe "MOODBOARD"
set scaling method to height
end tell
end tell
end tell
Model: Macbook Pro late 2015
AppleScript: 2.4
Browser: Safari 605.1.15
Operating System: macOS 10.14
It looks like a bug to me. Capture One also defines height and width properties, and AppleScript won’t allow two terms to differ only by case. I can’t see any workaround, unfortunately.
Initially, I thought it might be a case problem, as when I code I have it capitalised, then when it compiles it removes the capitalisation. Also, when compiled it does not recognise it as part of an enumeration.
I’ve managed to sidestep the issue completely, because each “recipe” is also stored as an xml file within the library.
This means that instead of changing the properties within the Capture One app of each “Recipe” I have overwritten the corresponding xml file with predefined data stored in my AppleScript file.
I recently came across this problem with Capture One 20. I’ve not upgraded to the latest version, which possibly fixes the issue.
I found a way round it, sort of, with Script Debugger (I’m on version 6).
Write any value for scaling method other than Width or Height. I suggest ‘Fixed’. Compile.
Switch Script Debugger to Raw (Chevron) Syntax, under the View menu. After doing this a few times, I quickly realised the benefit of creating a keyboard shortcut for this menu item in System Preferences…
Edit «constant CRstRsfx» to «constant CRstRswd» for Width or to «constant CRstRsht» for Height.
Optionally turn off Chevron syntax to confirm the result of the edit (you should see Width or Height), recompile, don’t make any further edits and save!
The catch is that, at least for me, any further edits and recompilation whilst not showing the Raw (Chevron) syntax, resets ‘Width’ and ‘Height’ back to ‘width’ and ‘height’… So you have to continually make this edit your last every time you work on the script and go through the steps above…
I tried baking these changes into a small dedicated script that was called from the larger script I was working on. I passed the recipe name to the called script and had it set the scaling method to Width, etc. However, sadly, although the called script seemed to report that the recipe object’s scaling method was correctly set, this was not reflected in the UI. I may have done something wrong here and I feel I need to do more investigation. It may just be easier than working on the XML data. But thanks for this pointer!
Hope this helps anyone with Capture One 20…
Quentin
Edit: I’ve had some success in automating steps 2 to 4 above with a Script Debugger script… Is this metaprogramming?
My first Script Debugger script to help out here. Some explanations in the script below:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
-- Capture One 20 bug: scaling method enumerators Height and Width
-- clash with height and width properties of focus meter.
-- But we can set Height and Width by specifying the raw syntax in Script Debugger's
-- Raw (Chevron) Syntax display mode and then compiling. This script automates the process.
-- Note that subsequent script edits destroy the corrections made (at least with Capture One 20).
-- Script tested with version 6.0.8 of Script Debugger.
-- The script is a little basic in just replacing all occurrences of
-- 'scaling method to width' and 'scaling method to height' with:
-- 'scaling method to Width' and 'scaling method to Height'.
-- So keep your Capture One script simple by employing these precise terms
-- only where they apply and it should work.
-- What 'scaling method to width' shows as raw text
property errantWidthPropertySetting : "«property CSmt» to «property Cwid»"
-- What 'scaling method to height' shows as raw text
property errantHeightPropertySetting : "«property CSmt» to «property Chgt»"
-- Desired settings:
property desiredWidthPropertySetting : "«property CSmt» to «constant CRstRswd»"
property desiredHeightPropertySetting : "«property CSmt» to «constant CRstRsht»"
-- classes, constants, and enums used
property NSMutableString : a reference to current application's NSMutableString
tell application "Script Debugger"
-- This script cannot be a target if it's open (development sanity saver).
set myName to my name & ".scpt"
set ddd to name of documents whose name is not myName
-- If more than one script is open in Script Debugger, allow user to choose the target.
if (count of ddd) > 1 then
set docName to (choose from list ddd with prompt "Select script to process:" with title my name)
if docName is false then
return
else
set docName to item 1 of docName
end if
else
set docName to item 1 of ddd
end if
try
set doc to some document whose name is docName
on error
display dialog "Could not get " & docName buttons {"Cancel"} default button 1 with title "Capture One Recipe Scaling Method Bug Fix" with icon stop
end try
end tell
-- Switch to Raw (Chevron) Syntax
tell doc
compile
set show raw syntax to true
end tell
-- Do the replacements using ASObjC for speed.
set replacementsMade to (replaceAll of me given |script|:doc)
-- Switch back to normal syntax
tell doc
compile
set show raw syntax to false
save
end tell
-- Report
tell application "Script Debugger"
display dialog "Replaced in script '" & docName & "':" & linefeed & linefeed & "Height:" & tab & item 1 of replacementsMade & linefeed & "Width:" & tab & item 2 of replacementsMade buttons {"OK"} default button "OK" with title my name with icon 1
end tell
-- Keep ASObjC code in handlers to allow property persistence (if required in future versions?)
on replaceAll given |script|:doc
set scriptSource to NSMutableString's stringWithString:(get doc's source text)
set scriptRange to {location:0, |length|:scriptSource's |length|()}
-- Replace height property with Height enumerator
set noHeightReplacements to scriptSource's replaceOccurrencesOfString:errantHeightPropertySetting withString:desiredHeightPropertySetting options:0 range:scriptRange
-- document has resized
set scriptRange to {location:0, |length|:scriptSource's |length|()}
-- Replace width property with Width enumerator
set noWidthReplacements to scriptSource's replaceOccurrencesOfString:errantWidthPropertySetting withString:desiredWidthPropertySetting options:0 range:scriptRange
set doc's source text to (scriptSource as text)
return {noHeightReplacements, noWidthReplacements}
end replaceAll