Score:0

How to toggle between 2 specific resolutions via keyboard shortcut?

in flag

I'm using Ubuntu on a laptop (with its built-in screen disabled) connected to a 3840x2160 external display.

Before sharing my screen on a video chat, I always like to switch the resolution down to 1920x1080.

I want to be able to quickly toggle the resolution of my external display between 3840x2160 and 1920x1080 via a keyboard shortcut, such as SuperPrntScrn.

This really old answer might be relevant as a starting place, but I'm not sure where to go from here.

As an example (but not on Ubuntu), I was able to do it on a Macbook following this answer.

Score:0
in flag

This answer was more helpful than I originally realized.

  1. In Ubuntu 20.04, go to Settings → Displays.
  2. In the Resolution dropdown, count the position of the resolution options that you care about. (In the screenshot below, "3840 x 2160" is 1st, and "1920 x 1080" is 7th.)
  3. In Terminal, xrandr -s 0 -r 30.00 will set the system to use the 1st resolution at 30 Hz (or 29.98 Hz actually, somehow), and xrandr -s 6 -r 30.00 will switch to the 7th. Test those commands.
  4. vim toggle_resolution.sh and paste the sample bash script shown below (and edit as necessary).
  5. chmod +x toggle_resolution.sh
  6. Run ./toggle_resolution.sh a couple times to test the toggling.
  7. You could create a hotkey in Settings → Keyboard Shortcuts to run that bash script file.

Settings → Displays

Sample bash script:

#!/bin/bash

# https://askubuntu.com/a/1351112/48214
X=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1)
# echo "$X"

if [ $X == 3840 ]
then
        xrandr -s 6 -r 30.00
else
        xrandr -s 0 -r 30.00
fi
Rudy Vissers avatar
de flag
Nice. Do you know why the max refresh rate is not selected by default?
Ryan avatar
in flag
@RudyVissers No
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.