I recently started developing full-time in Vim again because all my code has to run on remote virtual machines. I like using iTerm2 with some transparency enabled so I can see what’s going on in my browser, but it’s started giving me a headache now that I’m spending all day in my terminal. I couldn’t find a built-in hotkey for toggling transparency in iTerm2, so I cooked something up with AppleScript.
- Launch Automator, which comes pre-installed with your Mac.
- When prompted for a new document type, select “Service”.
- In the “Actions” tab on the left, search for “applescript”.
- Drag the “Run AppleScript” result into the window on the right.
Copy and paste this script into the text area, then hit the hammer icon to build it.
tell application "iTerm" if the transparency of the current session of the current window > 0 then repeat with aWindow in windows tell aWindow repeat with aTab in tabs of aWindow repeat with aSession in sessions of aTab tell aSession set transparency to 0 end tell end repeat end repeat end tell end repeat else repeat with aWindow in windows tell aWindow repeat with aTab in tabs of aWindow repeat with aSession in sessions of aTab tell aSession set transparency to 0.3 end tell end repeat end repeat end tell end repeat end if end tell
- Change the dropdown boxes on top so that they read “Service receives no input in iTerm”. You may have to click “Other…” in order to select iTerm.
- Save this as “Toggle Transparency”.
- Open System Preferences, and go to the Keyboard section, then the Shortcuts tab, then the Services category.
- Click on “Add Shortcut” next to “Toggle Transparency”, and record a key combination. I use
Cmd + Shift + U.
Try it out! Open iTerm2, and hit your key combination a few times. You can also run the script by click on iTerm2 in your menu bar and going to Services. You may want to tweak the AppleScript I provided if your default profile has transparency because my default profile does not have transparency. Just flip the transparency values of