Here, FWIW, is an AppleScript which I use to toggle Bike between my usual working colors (amber text against a dark chocolate background), and a temporary black ink on white background.
You should be able to replace my color values with your own.
An RGB color is specified as an AppleScript list of 3 integers, each in the range {0…65535}, or to put it another way {1…(2 ^ 16) - 1}.
(Click the copy icon at top right of the code)
tell application "Bike"
-- In AppleScript the return values from
-- {background color, foreground color}
-- are integers in the range [0..65535]
-- but the same properties in JS seems to get floats (in the range 0..1)
-- also, using the properties JS always seems to yield black background
-- and black foreground, regardless of input values.
set white to ((255 / 255) * 65535) as integer
set black to ((23 / 255) * 65535) as integer
-- Black ink on white paper
set light to {{white, white, white}, {black, black, black}}
-- Chocolate and orange.
set dark to {{8736, 8736, 8736}, {65535, 51656, 37008}}
-- The return values of these two properties seem to get
-- accidentally swapped in the API, just after a colors
-- reset in Preferences, when foregroundColor gives us
-- the background, and vice versa.
set {nBack, nFore} to {foreground color, background color}
if (item 1 of nBack) < (item 1 of item 1 of dark) then
set {background color, foreground color} to dark
else
set {background color, foreground color} to light
end if
end tell
Two footnotes on Bike colors scripting in case of confusion:
- In the current preview build (1.7: 90) something about
Preferences > Editor > Reset Colors
seems to temporarily confuse the scripting interface, if theAppearance
mode isLight
, and it appears to initially (just once) return a foreground value in place of the background value, and vice versa. (See test script below) - Some kind of type conversion glitch seems to be confounding the setting of these properties if we use JavaScript for Automation, so AppleScript only, at the moment, I think.
To test an apparent scripting interface glitch immediately after Preferences > Editor > Reset Colors
:
- Choose
Preferences > General > Light
- Click
Preferences > Editor > Reset Colors
- Try running the script below. On this system, the screen colors are unexpectedly inverted on first run, but the inversion doesn’t repeat thereafter.
tell application "Bike"
set {backColor, foreColor} to {background color, foreground color}
set {background color, foreground color} to {backColor, foreColor}
end tell