0

I've tried just about everything to figure out a way to automatically bump up the font size much larger when I hit a hot key in tmux by triggering a script. Only thing I got working is this which is very hacky and slow:

#!/usr/bin/env bash

osascript -e '
tell application "System Events" to keystroke "++++++++++++++++++++" using command down
'

This works but only with shell integration:

echo -e "\033]50;SetProfile=Development_Large\a"

But the problem is shell integration does not work with tmux.

Anything else I can do? I've tried applescript to change the current profile but I could not get any of them to work. Example:

osascript -e "
tell application \"iTerm2\"
  tell current window
    tell current tab
      set profile to \"cheat\"
    end tell
  end tell
end tell
"

This script just outputs "cheat" to the terminal.

Is there something else I might try?

3
  • This works: create tab with profile "Development_Large" But I want to change the profile of the current tab.
    – StevieD
    Aug 18, 2021 at 14:57
  • 1
    RE: "This works: create tab with profile "Development_Large" -- Yes, because with profile is a part of the AppleScript dictionary of ITerm2, its a property. profile as in set profile to ... is not a part of the AppleScript dictionary of ITerm2, and in its context it is nothing more than a variable to which cheat was assigned. -- RE: "But I want to change the profile of the current tab" -- Looking at the AppleScript dictionary of ITerm2, I do not see a mechanism by which to do that with AppleScript. Aug 18, 2021 at 15:25
  • I just found a solution. Will post.
    – StevieD
    Aug 18, 2021 at 15:26

1 Answer 1

1

I hit upon a solution:

Step 1: In iterm, open the preferences panel for the profile you will be switching from

Step 2: Click on the "Keys" tab for the profile

Step 3: Add a new key mapping by clicking on the plus sign.

Step 4: Choose the "keyboard shortcut" as desired and under "action", select "change profile". Now select the profile you want to switch to. Click "OK"

Step 5: Use something like the following bash script to trigger the key mapping:

osascript -e 'tell application "System Events" to keystroke "z" using {command down,control down}'

You will need to modify this script to use your chosen hotkey.

One other very useful but somewhat unrelated tip for modifying fonts is to give tmux the "resize-window" command to fix the window size. This prevents the panes from resizing when switching font sizes.

4
  • Because this is part of a command used with a tmux hotkey: bind E resize-pane -Z \; run-shell "bash -c ~/bin/profile.sh"
    – StevieD
    Aug 18, 2021 at 15:47
  • The above key bind for tmux will zoom the pane to take up the whole screen and resize the font. And I have another keybind to zoom out.
    – StevieD
    Aug 18, 2021 at 15:47
  • Can you elaborate on the resize-window comment? I want iTerm2 to stop resizing the window when increasing font size in tmux. It doesn't resize the window for my default profile.
    – Al Johri
    Jan 7, 2022 at 22:27
  • I don't recall the details but I've got this in my tmux config file: bind E resize-pane -Z \; run-shell "bash -c ~/bin/profile.sh; sleep 0.3" \; resize-window -A
    – StevieD
    Jan 8, 2022 at 3:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .