Does anyone know how I can findout (with Java-Script in BTT) what the color ("1F1F1F")
is at a given x,y screen position ?
I want to store that color in a user BTT variable,
so that I define triggers based on an advanded condition (which can use that user BTT variable)
I am using Ableton Live and the purpose would be to find out what the 'state' the app / screen is in.
for example:
Whether the screen 'shows' the Ableton Play button in green or in white,
or if the 'detailed info' is displayed, etc, etc.
Without knowing that 'state', I trigger now actions which are sometimes not 'valid' in that context ( as for example nothing is playing, i.e. button=green )
Thx,
Christian
Running:
BTT 3.998 (2170) / Mac M1 Max OS Ventura 13.1 /
BTT plugin Stream Deck option
Stream Deck Mobile (on iPad Air) latest version
Not with JavaScript but with AppleScript and also only with the help of the clipboard (screenshot):
use framework "AppKit"
use framework "Foundation"
use framework "QuartzCore"
use scripting additions
set xCoordinate to 100
set yCoordinate to 100
set {redColor, greenColor, blueColor} to getRGBData(xCoordinate, yCoordinate)
set hexValue to (do shell script "printf " & quoted form of "#%02X%02X%02X" & " " & redColor & " " & greenColor & " " & blueColor)
tell application "BetterTouchTool"
set_string_variable "screenColorAtPoint" to hexValue
end tell
on getRGBData(xCoordinate, yCoordinate)
do shell script "screencapture -R " & xCoordinate & "," & yCoordinate & ",1,1 -c"
set imageData to (current application's NSPasteboard's generalPasteboard()'s dataForType:(current application's NSPasteboardTypeTIFF))
set theImage to (current application's CIImage's imageWithData:imageData)
set imageRep to (current application's NSBitmapImageRep's alloc()'s initWithCIImage:theImage)
set theColors to (imageRep's colorAtX:0 y:0)
set theColors to theColors's colorUsingColorSpace:(current application's NSColorSpace's genericRGBColorSpace())
set redColor to ((theColors's redComponent()) * 255) as integer
set greenColor to ((theColors's greenComponent()) * 255) as integer
set blueColor to ((theColors's blueComponent()) * 255) as integer
return {redColor, greenColor, blueColor}
end getRGBData
Here is a version without clipboard (via temp file):
use framework "AppKit"
use framework "Foundation"
use framework "QuartzCore"
use scripting additions
set xCoordinate to 100
set yCoordinate to 100
set {redColor, greenColor, blueColor} to getRGBData(xCoordinate, yCoordinate)
set hexValue to (do shell script "printf " & quoted form of "#%02X%02X%02X" & " " & redColor & " " & greenColor & " " & blueColor)
tell application "BetterTouchTool"
set_string_variable "screenColorAtPoint" to hexValue
end tell
on getRGBData(xCoordinate, yCoordinate)
set imagePath to POSIX path of ((path to temporary items folder as text) & "image.png")
do shell script "screencapture -R " & xCoordinate & "," & yCoordinate & ",1,1 " & imagePath
set imageRep to current application's NSBitmapImageRep's imageRepWithContentsOfFile:imagePath
set theColors to (imageRep's colorAtX:0 y:0)
set theColors to theColors's colorUsingColorSpace:(current application's NSColorSpace's genericRGBColorSpace())
set redColor to ((theColors's redComponent()) * 255) as integer
set greenColor to ((theColors's greenComponent()) * 255) as integer
set blueColor to ((theColors's blueComponent()) * 255) as integer
do shell script "rm " & imagePath
return {redColor, greenColor, blueColor}
end getRGBData
I am on BetterTouchTool 3.9981 ...ist zurzeit die neueste verfügbare Version....
but somehow the get_string_variable "color_under_cursor" part
does not yet work ?
tell application "BetterTouchTool"
set xy to get_string_variable "color_under_cursor"
set_string_variable "screenColorAtPoint" to xy
end tell
I noticed that there is a variable created after the action "Save Mouse position" is run
like → saved_mouse_position: {717.26171875, 350.6171875}
If I change that variable to a differnt value like
saved_mouse_position: {100, 100}
why is "Restore Mouse Position" not 'moving' the cursor to that (new) position ?
Thx,
Christian
Running:
BTT 3.998 (2170) / Mac M1 Max OS Ventura 13.1 /
BTT plugin Stream Deck option
Stream Deck Mobile (on iPad Air) latest version
tell application "BetterTouchTool"
set xy to get_string_variable "color_under_cursor"
set_string_variable "screenColorAtPoint" to xy
set mouse_xy to get_string_variable "saved_mouse_position"
set_string_variable "mouse_xy" to mouse_xy
set org_mouse_xy to get_string_variable "org_mouse_xy"
set_string_variable "saved_mouse_position" to org_mouse_xy
end tell
then right after that Apple script I call the "restore mouse position" action...
but the cursors stays at {540, 80}