Script for Davinci Resolve conform

Hello everyone, I’m new to the forum so hopefully I’m not breaking any rules here.
I just want to share some progress I have made to automate conforming process in DaVinci resolve.


set {redColor, blueColor, greenColor} to {missing value, missing value, missing value}
set {redColor1, blueColor1, greenColor1} to {missing value, missing value, missing value}
set {redColor2, blueColor2, greenColor2} to {missing value, missing value, missing value}
set {redColor3, blueColor3, greenColor3} to {missing value, missing value, missing value}
set {redColor4, blueColor4, greenColor4} to {missing value, missing value, missing value}

repeat 60 times
	do shell script "/usr/local/bin/cliclick m:" & "1885,450"
	tell application "Digital Color Meter" to activate
	tell application "System Events"
		tell process "Digital Color Meter"
			click menu item "Copy Color as Text" of menu 1 of menu bar item "Color" of menu bar 1
		end tell
	end tell
	set rgbColors to words of (the clipboard)
	if (count of rgbColors) is 3 then
		set {redColor, blueColor, greenColor} to {item 1 of rgbColors, item 2 of rgbColors, item 3 of rgbColors}
	end if
	
	do shell script "/usr/local/bin/cliclick m:" & "2480,550"
	tell application "Digital Color Meter" to activate
	tell application "System Events"
		tell process "Digital Color Meter"
			click menu item "Copy Color as Text" of menu 1 of menu bar item "Color" of menu bar 1
		end tell
	end tell
	set rgbColors to words of (the clipboard)
	if (count of rgbColors) is 3 then
		set {redColor1, blueColor1, greenColor1} to {item 1 of rgbColors, item 2 of rgbColors, item 3 of rgbColors}
	end if
	
	do shell script "/usr/local/bin/cliclick m:" & "2480,170"
	tell application "Digital Color Meter" to activate
	tell application "System Events"
		tell process "Digital Color Meter"
			click menu item "Copy Color as Text" of menu 1 of menu bar item "Color" of menu bar 1
		end tell
	end tell
	set rgbColors to words of (the clipboard)
	if (count of rgbColors) is 3 then
		set {redColor2, blueColor2, greenColor2} to {item 1 of rgbColors, item 2 of rgbColors, item 3 of rgbColors}
	end if
	
	do shell script "/usr/local/bin/cliclick m:" & "1750,180"
	tell application "Digital Color Meter" to activate
	tell application "System Events"
		tell process "Digital Color Meter"
			click menu item "Copy Color as Text" of menu 1 of menu bar item "Color" of menu bar 1
		end tell
	end tell
	set rgbColors to words of (the clipboard)
	if (count of rgbColors) is 3 then
		set {redColor3, blueColor3, greenColor3} to {item 1 of rgbColors, item 2 of rgbColors, item 3 of rgbColors}
	end if
	
	do shell script "/usr/local/bin/cliclick m:" & "2110,570"
	tell application "Digital Color Meter" to activate
	tell application "System Events"
		tell process "Digital Color Meter"
			click menu item "Copy Color as Text" of menu 1 of menu bar item "Color" of menu bar 1
		end tell
	end tell
	set rgbColors to words of (the clipboard)
	if (count of rgbColors) is 3 then
		set {redColor4, blueColor4, greenColor4} to {item 1 of rgbColors, item 2 of rgbColors, item 3 of rgbColors}
	end if
	
	set redColor to redColor as number
	set blueColor to blueColor as number
	set greenColor to greenColor as number
	set redColor1 to redColor1 as number
	set blueColor1 to blueColor1 as number
	set greenColor1 to greenColor1 as number
	set redColor2 to redColor2 as number
	set blueColor2 to blueColor2 as number
	set greenColor2 to greenColor2 as number
	set redColor3 to redColor3 as number
	set blueColor3 to blueColor3 as number
	set greenColor3 to greenColor3 as number
	set redColor4 to redColor4 as number
	set blueColor4 to blueColor4 as number
	set greenColor4 to greenColor4 as number
	
	if redColor < 10 and blueColor < 10 and greenColor < 10 and redColor1 < 10 and blueColor1 < 10 and greenColor1 < 10 and redColor2 < 10 and blueColor2 < 10 and greenColor2 < 10 and redColor3 < 10 and blueColor3 < 10 and greenColor3 < 10 and redColor4 < 10 and blueColor4 < 10 and greenColor4 < 10 then
		activate application "DaVinci Resolve"
		tell application "System Events"
			delay 0.2
			key code 125
		end tell
	else
		activate application "DaVinci Resolve"
		tell application "System Events"
			delay 0.2
			key code 43
		end tell
	end if
end repeat

So basically I’m trying to use default mac color picker to identity my preview screen and trying to match my source clip with reference clip at the correct frame. I move my source clip one frame at the time and once my screen is black, (I have ‘difference’ filter turned on) that means the clips are matched.
The problem I have however, is that color picker only picks up a small percentage of the frame, so currently I have to create 5 points, but it’s still not enough. I’m wondering if there is a better way to achieve this, preferably in applescript.

PS: I know my code probably looks horrendous, but it’s the best I can do right now :frowning:

Welcome to the forum.

One way you could try is to get the values for an area by taking a screenshot, and then use Core Image to get the average for the area. That returns a single pixel with the average color, and you can test that. So:

use AppleScript version "2.5" -- macOS 10.11 or later
use framework "Foundation"
use framework "AppKit"
use framework "QuartzCore"
use scripting additions

-- change coords to suit
set theX to 0
set theY to 0
set theWidth to 100
set theHeight to 100
do shell script "screencapture -R " & theX & "," & theY & "," & theWidth & "," & theHeight & " -c"
set theData to current application's NSPasteboard's generalPasteboard()'s dataForType:(current application's NSPasteboardTypeTIFF)
set theCIImage to current application's CIImage's imageWithData:theData
set theCIFilter to current application's CIFilter's filterWithName:"CIAreaAverage"
theCIFilter's setValue:theCIImage forKey:(current application's kCIInputImageKey)
set theResult to theCIFilter's valueForKey:(current application's kCIOutputImageKey)
set thisRep to current application's NSBitmapImageRep's alloc()'s initWithCIImage:theResult
set theColor to (thisRep's colorAtX:0 y:0)
set theR to theColor's redComponent()
set theG to theColor's greenComponent()
set theB to theColor's blueComponent()
set theAlpha to theColor's alphaComponent()

Wow, that’s exactly what i’m looking for, thanks!
Just one more question. My script needs to run for a long period of time, would taking screencapture affect my storage or memory in a negative way? Or they just gone once they are processed?
Again, thanks for helping me out.

It’s just saving them to the clipboard, and you wouldn’t make them bigger than you need to. There’s bound to be some memory leakage, but I doubt it would have much impact unless you ran it without quitting for a long time. The real answer, though, will come from trying it.

Great, I guess I will just have to test it to know for sure then. Thanks for the heads up, I appreciate it.

I added do shell script “pbcopy </dev/null”
to make sure clipboard is cleared after each run. Not sure if this is any useful.

It will be a tad quicker to use:

current application's NSPasteboard's generalPasteboard()'s clearContents()

But I’m not sure I see the point. It gets called every time the clipboard gets replaced anyhow.

Thanks for your quick reply. Yeah, my script works to a certain extend but now I’m just trying to optimize it so it could be implemented in real world environment.
I’m stuck trying to figure out how to stop the loop manually with key presses. Is it possible in apple script?

You can check for modifier keys. For example:

use framework "Foundation"
use framework "AppKit" 

-- classes, constants, and enums used
property NSAlternateKeyMask : a reference to 524288

set optionDown to ((current application's NSEvent's modifierFlags()) div NSAlternateKeyMask) mod 2 as boolean

weird, I’m only getting false even if I keep pressing all my modifier keys. Does it have anything to do with Catalina?

It’s not going to keep checking – you’d need to have it in some kind of loop.

thanks I did include a loop, but I put your code outside the loop facepalm… my bad