Trigger Eyedropper Tool with AppleScript in Mac Color Picker

applescriptcolor

I'd like to be able to use an eyedropper tool on command. The built-in Mac colour picker is nice, so to that end, I set up a keyboard shortcut using BetterTouchTool to open the colour picker; it does so simply by running the choose color AppleScript command.

This is only a partial solution, because I still need to click the eyedropper icon to get what I want. Apart from the minor nuisance of an extraneous click, the problem is that the click itself changes focus away from the application I'm using. (For example, suppose I'm using the eyedropper to test the :focus state of an element on a website.)

Is there a way to tell my script to run the eyedropper tool after opening the colour picker? In other words, I would like to automatically click the button indicated in this screenshot:

enter image description here

Best Answer

Updated Answer

I download the trial of BetterTouchTool and resolved the issue in the following manner:

  1. Added a keyboard shortcut assigning it: ⇧⌃P
  2. Added the built-in Show Color Picker action to the aforementioned keyboard shortcut.
  3. Added a Run AppleScript (async in background) action, to the aforementioned keyboard shortcut, with the following AppleScript code:
    tell application "System Events" to ¬
        click (checkbox 1 of ¬
            splitter group 1 of ¬
            window "Colors" of ¬
            application process "BetterTouchTool")

Note that this was done under macOS Big Sur and it works without issue after the initial setup and permissions setting as were prompted.

Now when I press ⇧⌃P the Color window opens and the color picker button is clicked, and it is active to select a color where the mouse pointer was when the keyboard shortcut was pressed.


Original Answer

I do not have BetterTouchTool, so using Script Editor I find that if one just runs the choose color command, the Colors window is modal and does not allow any additional code that would click the color picker button to run.

To work around this, the choose color command can be wrapped within an ignoring application responses statement. However, while this allows the color picker button to be clicked by additional code, one does not get back, e.g. {14896, 20151, 65429} from the choose color command when the OK button is cliched after picking the color.

Example AppleScript code:

ignoring application responses
    choose color
end ignoring

delay 0.5

tell application "System Events" to ¬
    click (checkbox 1 of ¬
        splitter group 1 of ¬
        window "Colors" of ¬
        application process "Script Editor")

This was tested under macOS Catalina.