5

I'm trying to use AppleScript to change the background color of a Finder window and came across this code snippet, which seems to work... However, I'm not sure the logic of the color array...

tell the icon view options of the front Finder window
    set the background color to {52942, 54484, 31097}
end tell

What does the {52942, 54484, 31097} AppleScript magic refer to? It doesn't look like RGB to me... How would I get something specific like red (#ff0000 | 255, 0, 0) or, better yet, a neon cyan (#00f6ff | 0, 246, 255)?

1
  • When fiddling with the values, I receive this error: "Finder got an error: Can’t make {12242, 84282, 41097} into type RGB color."
    – jon.s
    Commented Mar 14, 2015 at 22:22

2 Answers 2

10

There are four different numeric representations of the RGB color.

Notation -- RGB triplet (red)

1- Arithmetic -- (1.0, 0.0, 0.0)

2- Percentage -- (100%, 0%, 0%)

3- Digital 8-bit per channel -- (255, 0, 0) or sometimes #FF0000 (hexadecimal)

4- Digital 16-bit per channel -- (65535, 0, 0)

The component values are often stored as integer numbers in the range 0 to 255, the range that a single 8-bit byte can offer. These are often represented as either decimal or hexadecimal numbers.

Multiply the integer (standard RGB value) by 257 to get the value in Digital 16-bit per channel (AppleScript)

0
2

You don’t have to work with the colors as numbers. There is a choose color command that shows the system color picker.

tell application "Finder"
    activate
    tell the icon view options of the front window
        set the background color to choose color
    end tell
end tell

… but for some reason, after running this script you will have to close and then reopen the Finder window to see the color change.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.