Default color as background

As we know very well, macOS has the option to select a default accent color.


However, the problem is when you want to choose this color, for example, as a background for the floating menu.
Therefore, it would be nice if, when selecting the colors of the elements, there was an option to simply choose the current color of the system accent.

Hi @MStankiewiczOfficial,

I’ve put together an AppleScript that should help achieve exactly what you described.

How It Works

Trigger:

The script is connected to a BTT trigger of the type “Received Distributed Notification With Name”. It listens for the AppleColorPreferencesChangedNotification – which is sent by macOS whenever the system’s accent color changes. This means that as soon as you change your accent color in System Settings, BTT automatically fires this trigger and runs our script.

Action:

When the trigger fires, the script performs the following steps:

• Reads the System Accent Color: It runs a shell command (defaults read -g AppleAccentColor) to fetch the current accent color code.

• Maps to RGB Values: Depending on the accent code, the script maps it to a specific RGB value (with comments indicating the corresponding color, e.g., Red, Orange, Yellow, etc.). For example, if the accent code is 0, it sets the RGB to 255, 82, 87 (Red). If no valid accent color is found (or it’s set to multicolor), it defaults to 108, 96, 190.

• Updates the Floating Menu Background: The script builds a JSON string with the RGB value and uses BetterTouchTool’s update_menu_item command to update the background color of a specified menu item (targeted by its UUID).

• Sets a Persistent Variable: Finally, it stores the current RGB value in a persistent string variable (accent_color_rgb). This variable can be referenced by any Floating Menu item in BTT, ensuring all related elements are automatically synced with your system accent.

Below is the commented script with detailed explanations for each step:

-- Attempt to read the system's current accent color using a shell command.
try
	-- This command returns a code corresponding to the current macOS accent color.
	set accentCode to do shell script "defaults read -g AppleAccentColor"
on error
	-- If the command fails (e.g., if no accent color is set), default accentCode to an empty string.
	set accentCode to ""
end try

-- Map the accent code to its corresponding RGB value, with comments indicating each color name.
if accentCode is equal to "" then
	-- If accentCode is empty, treat it as "multicolor" and assign the default RGB value.
	set colorRGB to "108, 96, 190" -- Multicolor
else if accentCode is equal to "-1" then
	-- Accent code -1 corresponds to "graphite".
	set colorRGB to "140, 140, 140" -- Graphite
else if accentCode is equal to "0" then
	-- Accent code 0 corresponds to "red".
	set colorRGB to "255, 82, 87" -- Red
else if accentCode is equal to "1" then
	-- Accent code 1 corresponds to "orange".
	set colorRGB to "247, 130, 27" -- Orange
else if accentCode is equal to "2" then
	-- Accent code 2 corresponds to "yellow".
	set colorRGB to "255, 198, 0" -- Yellow
else if accentCode is equal to "3" then
	-- Accent code 3 corresponds to "green".
	set colorRGB to "98, 186, 70" -- Green
else if accentCode is equal to "4" then
	-- Accent code 4 corresponds to "blue".
	set colorRGB to "0, 122, 255" -- Blue
else if accentCode is equal to "5" then
	-- Accent code 5 corresponds to "purple".
	set colorRGB to "165, 80, 167" -- Purple
else if accentCode is equal to "6" then
	-- Accent code 6 corresponds to "pink".
	set colorRGB to "247, 79, 158" -- Pink
else
	-- For any unexpected accent code, default to the multicolor RGB value.
	set colorRGB to "108, 96, 190" -- Multicolor (default)
end if

-- Build the JSON string with the dynamic RGB value for the menu item's background.
-- The JSON string formats the RGB value as 'rgb(r, g, b)'.
set jsonString to "{BTTMenuItemBackgroundColor: 'rgb(" & colorRGB & ")' }"

tell application "BetterTouchTool"
	-- Define the UUID for the specific menu item you want to update.
	-- Replace the UUID below with your own menu item's UUID.
	set UUID_OF_MENU_ITEM to "5CA836DD-3A32-4832-A65A-CFBEE8C9FBC9"
	
	-- Update the specified menu item by passing the UUID along with the constructed JSON string.
	update_menu_item UUID_OF_MENU_ITEM json jsonString
	
	-- Set a persistent string variable to store the current RGB accent color.
	-- This variable (named "accent_color_rgb") can be referenced by any Floating Menu item in BTT.
	set_persistent_string_variable "accent_color_rgb" to colorRGB
end tell

This setup ensures that your floating menus always reflect the current system accent color dynamically. Let me know if you have any questions.

Full BTT JSON config:

[
  {
    "BTTActionCategory" : 0,
    "BTTLastUpdatedAt" : 1742184595.572093,
    "BTTTriggerType" : 607,
    "BTTTriggerTypeDescriptionReadOnly" : "Received Distributed Notification: AppleColorPreferencesChangedNotification",
    "BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
    "BTTUUID" : "A6AD90EB-E043-4008-BE54-1853942AABF9",
    "BTTPredefinedActionType" : 366,
    "BTTPredefinedActionName" : "Empty Placeholder",
    "BTTDistributedNotificationName" : "AppleColorPreferencesChangedNotification",
    "BTTEnabled" : 1,
    "BTTEnabled2" : 1,
    "BTTOrder" : 2,
    "BTTAdditionalActions" : [
      {
        "BTTActionCategory" : 0,
        "BTTLastUpdatedAt" : 1742185759.0123239,
        "BTTTriggerParentUUID" : "A6AD90EB-E043-4008-BE54-1853942AABF9",
        "BTTIsPureAction" : true,
        "BTTTriggerClass" : "BTTTriggerTypeOtherTriggers",
        "BTTUUID" : "C32EB76C-3055-4E2E-8A54-DAE8822D3048",
        "BTTPredefinedActionType" : 195,
        "BTTPredefinedActionName" : "Run Apple Script (async in background)",
        "BTTAdditionalActionData" : {
          "BTTScriptType" : 0,
          "BTTAppleScriptString" : "-- Attempt to read the system's current accent color using a shell command.\rtry\r\t-- This command returns a code corresponding to the current macOS accent color.\r\tset accentCode to do shell script \"defaults read -g AppleAccentColor\"\ron error\r\t-- If the command fails (e.g., if no accent color is set), default accentCode to an empty string.\r\tset accentCode to \"\"\rend try\r\r-- Map the accent code to its corresponding RGB value, with comments indicating each color name.\rif accentCode is equal to \"\" then\r\t-- If accentCode is empty, treat it as \"multicolor\" and assign the default RGB value.\r\tset colorRGB to \"108, 96, 190\" -- Multicolor\relse if accentCode is equal to \"-1\" then\r\t-- Accent code -1 corresponds to \"graphite\".\r\tset colorRGB to \"140, 140, 140\" -- Graphite\relse if accentCode is equal to \"0\" then\r\t-- Accent code 0 corresponds to \"red\".\r\tset colorRGB to \"255, 82, 87\" -- Red\relse if accentCode is equal to \"1\" then\r\t-- Accent code 1 corresponds to \"orange\".\r\tset colorRGB to \"247, 130, 27\" -- Orange\relse if accentCode is equal to \"2\" then\r\t-- Accent code 2 corresponds to \"yellow\".\r\tset colorRGB to \"255, 198, 0\" -- Yellow\relse if accentCode is equal to \"3\" then\r\t-- Accent code 3 corresponds to \"green\".\r\tset colorRGB to \"98, 186, 70\" -- Green\relse if accentCode is equal to \"4\" then\r\t-- Accent code 4 corresponds to \"blue\".\r\tset colorRGB to \"0, 122, 255\" -- Blue\relse if accentCode is equal to \"5\" then\r\t-- Accent code 5 corresponds to \"purple\".\r\tset colorRGB to \"165, 80, 167\" -- Purple\relse if accentCode is equal to \"6\" then\r\t-- Accent code 6 corresponds to \"pink\".\r\tset colorRGB to \"247, 79, 158\" -- Pink\relse\r\t-- For any unexpected accent code, default to the multicolor RGB value.\r\tset colorRGB to \"108, 96, 190\" -- Multicolor (default)\rend if\r\r-- Build the JSON string with the dynamic RGB value for the menu item's background.\r-- The JSON string formats the RGB value as 'rgb(r, g, b)'.\rset jsonString to \"{BTTMenuItemBackgroundColor: 'rgb(\" & colorRGB & \")' }\"\r\rtell application \"BetterTouchTool\"\r\t-- Define the UUID for the specific menu item you want to update.\r\t-- Replace the UUID below with your own menu item's UUID.\r\tset UUID_OF_MENU_ITEM to \"5CA836DD-3A32-4832-A65A-CFBEE8C9FBC9\"\r\t\r\t-- Update the specified menu item by passing the UUID along with the constructed JSON string.\r\tupdate_menu_item UUID_OF_MENU_ITEM json jsonString\r\t\r\t-- Set a persistent string variable to store the current RGB accent color.\r\t-- This variable (named \"accent_color_rgb\") can be referenced by any Floating Menu item in BTT.\r\tset_persistent_string_variable \"accent_color_rgb\" to colorRGB\rend tell",
          "BTTAppleScriptUsePath" : false,
          "BTTAppleScriptRunInBackground" : true,
          "SelectedAction" : 252,
          "BTTScriptLocation" : 0
        },
        "BTTInlineAppleScript" : "-- Attempt to read the system's current accent color using a shell command.\rtry\r\t-- This command returns a code corresponding to the current macOS accent color.\r\tset accentCode to do shell script \"defaults read -g AppleAccentColor\"\ron error\r\t-- If the command fails (e.g., if no accent color is set), default accentCode to an empty string.\r\tset accentCode to \"\"\rend try\r\r-- Map the accent code to its corresponding RGB value, with comments indicating each color name.\rif accentCode is equal to \"\" then\r\t-- If accentCode is empty, treat it as \"multicolor\" and assign the default RGB value.\r\tset colorRGB to \"108, 96, 190\" -- Multicolor\relse if accentCode is equal to \"-1\" then\r\t-- Accent code -1 corresponds to \"graphite\".\r\tset colorRGB to \"140, 140, 140\" -- Graphite\relse if accentCode is equal to \"0\" then\r\t-- Accent code 0 corresponds to \"red\".\r\tset colorRGB to \"255, 82, 87\" -- Red\relse if accentCode is equal to \"1\" then\r\t-- Accent code 1 corresponds to \"orange\".\r\tset colorRGB to \"247, 130, 27\" -- Orange\relse if accentCode is equal to \"2\" then\r\t-- Accent code 2 corresponds to \"yellow\".\r\tset colorRGB to \"255, 198, 0\" -- Yellow\relse if accentCode is equal to \"3\" then\r\t-- Accent code 3 corresponds to \"green\".\r\tset colorRGB to \"98, 186, 70\" -- Green\relse if accentCode is equal to \"4\" then\r\t-- Accent code 4 corresponds to \"blue\".\r\tset colorRGB to \"0, 122, 255\" -- Blue\relse if accentCode is equal to \"5\" then\r\t-- Accent code 5 corresponds to \"purple\".\r\tset colorRGB to \"165, 80, 167\" -- Purple\relse if accentCode is equal to \"6\" then\r\t-- Accent code 6 corresponds to \"pink\".\r\tset colorRGB to \"247, 79, 158\" -- Pink\relse\r\t-- For any unexpected accent code, default to the multicolor RGB value.\r\tset colorRGB to \"108, 96, 190\" -- Multicolor (default)\rend if\r\r-- Build the JSON string with the dynamic RGB value for the menu item's background.\r-- The JSON string formats the RGB value as 'rgb(r, g, b)'.\rset jsonString to \"{BTTMenuItemBackgroundColor: 'rgb(\" & colorRGB & \")' }\"\r\rtell application \"BetterTouchTool\"\r\t-- Define the UUID for the specific menu item you want to update.\r\t-- Replace the UUID below with your own menu item's UUID.\r\tset UUID_OF_MENU_ITEM to \"5CA836DD-3A32-4832-A65A-CFBEE8C9FBC9\"\r\t\r\t-- Update the specified menu item by passing the UUID along with the constructed JSON string.\r\tupdate_menu_item UUID_OF_MENU_ITEM json jsonString\r\t\r\t-- Set a persistent string variable to store the current RGB accent color.\r\t-- This variable (named \"accent_color_rgb\") can be referenced by any Floating Menu item in BTT.\r\tset_persistent_string_variable \"accent_color_rgb\" to colorRGB\rend tell",
        "BTTEnabled" : 1,
        "BTTEnabled2" : 1,
        "BTTOrder" : 742
      }
    ]
  }
]
2 Likes

Amazing! Thank you!