Skip to content

Instantly share code, notes, and snippets.

@thinkyhead
Created December 3, 2023 04:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkyhead/3ef1b407a736522119861edd4d4cc14b to your computer and use it in GitHub Desktop.
Save thinkyhead/3ef1b407a736522119861edd4d4cc14b to your computer and use it in GitHub Desktop.
Randomize Terminal Colors, watch for Appearance change
--
-- 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.
--
-- 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
--
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), -9000}
end rndcolor
on rndterm(dark)
tell application "Terminal"
if dark then
set txtcolor to {65535, 65535, 65535}
set bldcolor to {65535, 65535, 0}
else
set txtcolor to {0, 0, 0}
set bldcolor to {16384, 16384, 0}
end if
repeat with win in windows
if visible of win then
repeat with atab in every tab of win
set curr to current settings of (contents of atab)
set background color of curr to rndcolor(dark) of me
set normal text color of curr to txtcolor
set bold text color of curr to bldcolor
end repeat
end if
end repeat
end tell
end rndterm
global interval, isdark, wasdark
on run
set interval to 2 -- seconds
set isdark to getdark()
set wasdark to not isdark
end run
on idle
set isdark to getdark() of me
if isdark is not equal to wasdark then
set wasdark to 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