Skip to content

Commit 1f6ead4

Browse files
alrramathiasbynens
authored andcommitted
.osx: Fix code that sets the custom terminal theme
Fix the `.osx` script so that it correctly sets the custom terminal theme, and the change will be persistent. Closes mathiasbynens#492.
1 parent fdb4c90 commit 1f6ead4

File tree

1 file changed

+45
-8
lines changed

1 file changed

+45
-8
lines changed

.osx

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -564,14 +564,51 @@ sudo mdutil -E / > /dev/null
564564
defaults write com.apple.terminal StringEncodings -array 4
565565

566566
# Use a modified version of the Solarized Dark theme by default in Terminal.app
567-
TERM_PROFILE='Solarized Dark xterm-256color';
568-
CURRENT_PROFILE="$(defaults read com.apple.terminal 'Default Window Settings')";
569-
if [ "${CURRENT_PROFILE}" != "${TERM_PROFILE}" ]; then
570-
open "${HOME}/init/${TERM_PROFILE}.terminal";
571-
sleep 1; # Wait a bit to make sure the theme is loaded
572-
defaults write com.apple.terminal 'Default Window Settings' -string "${TERM_PROFILE}";
573-
defaults write com.apple.terminal 'Startup Window Settings' -string "${TERM_PROFILE}";
574-
fi;
567+
osascript <<EOD
568+
569+
tell application "Terminal"
570+
571+
local allOpenedWindows
572+
local initialOpenedWindows
573+
local windowID
574+
set themeName to "Solarized Dark xterm-256color"
575+
576+
(* Store the IDs of all the open terminal windows. *)
577+
set initialOpenedWindows to id of every window
578+
579+
(* Open the custom theme so that it gets added to the list
580+
of available terminal themes (note: this will open two
581+
additional terminal windows). *)
582+
do shell script "open '$HOME/init/" & themeName & ".terminal'"
583+
584+
(* Wait a little bit to ensure that the custom theme is added. *)
585+
delay 1
586+
587+
(* Set the custom theme as the default terminal theme. *)
588+
set default settings to settings set themeName
589+
590+
(* Get the IDs of all the currently opened terminal windows. *)
591+
set allOpenedWindows to id of every window
592+
593+
repeat with windowID in allOpenedWindows
594+
595+
(* Close the additional windows that were opened in order
596+
to add the custom theme to the list of terminal themes. *)
597+
if initialOpenedWindows does not contain windowID then
598+
close (every window whose id is windowID)
599+
600+
(* Change the theme for the initial opened terminal windows
601+
to remove the need to close them in order for the custom
602+
theme to be applied. *)
603+
else
604+
set current settings of tabs of (every window whose id is windowID) to settings set themeName
605+
end if
606+
607+
end repeat
608+
609+
end tell
610+
611+
EOD
575612

576613
# Enable “focus follows mouse” for Terminal.app and all X11 apps
577614
# i.e. hover over a window and start typing in it without clicking first

0 commit comments

Comments
 (0)