Last active
September 2, 2025 20:32
-
-
Save thinkyhead/3ef1b407a736522119861edd4d4cc14b to your computer and use it in GitHub Desktop.
Randomize Terminal Colors, watch for Appearance change
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- termcolor - Set all open Terminal tabs to a random color based on Dark mode. | |
-- Stay open and check for a change in Dark mode every couple of seconds. | |
-- When Dark Mode changes update the background color of all Terminal tabs. | |
-- | |
-- Possible enhancements: | |
-- • Watch for a new tab and set its colors. Alternative to the 'rndterm' perl script. | |
-- • Remember the background colors and retain the hue when dark mode changes. | |
-- | |
-- To make the exported application into a hidden background app: | |
-- defaults write /Path/to/termcolor.app/Contents/Info LSUIElement 1 | |
-- | |
-- Thinkyhead - 2 Dec 2023 - CC-NC-BY | |
-- | |
-- Updated - 2 Sep 2025 | |
-- | |
on getdark() | |
set dark to (do shell script "defaults read -g AppleInterfaceStyle 2>/dev/null | grep -i dark ; exit 0") | |
return (dark is equal to "Dark") | |
end getdark | |
on rndcomp(base) | |
return base + (random number from 0 to 20000) | |
end rndcomp | |
on rndcolor(dark) | |
if dark then | |
set n to 0 | |
else | |
set n to 45500 | |
end if | |
return {rndcomp(n), rndcomp(n), rndcomp(n), 0.5} | |
end rndcolor | |
on rndterm(dark) | |
tell application "Terminal" | |
if dark then | |
set fgcolors to {normal text color:"white", bold text color:"yellow", cursor color:"yellow"} | |
else | |
set fgcolors to {normal text color:"black", bold text color:"brown", cursor color:"blue"} | |
end if | |
repeat with win in windows | |
try | |
if visible of win then | |
repeat with atab in tabs of win | |
set curr to current settings of (contents of atab) | |
set background color of curr to rndcolor(dark) of me | |
set properties of curr to fgcolors | |
end repeat | |
end if | |
on error | |
-- ignore unusual windows | |
end try | |
end repeat | |
end tell | |
end rndterm | |
global interval, isdark, wasdark | |
on run | |
set interval to 2 -- seconds | |
set isdark to getdark() | |
--rndterm(isdark) | |
end run | |
on idle | |
if isdark is not equal to getdark() then | |
set isdark to not isdark | |
rndterm(isdark) | |
end if | |
return interval | |
end idle | |
on quit | |
continue quit | |
end quit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment