Skip to content

Instantly share code, notes, and snippets.

@stefanwatt
Created February 11, 2023 01:16
Show Gist options
  • Save stefanwatt/f5a04aac22e33f8c6c726e466e6944c5 to your computer and use it in GitHub Desktop.
Save stefanwatt/f5a04aac22e33f8c6c726e466e6944c5 to your computer and use it in GitHub Desktop.
switch resolution
#!/usr/bin/env node
import childProcess from "node:child_process";
import { promisify } from "util";
const UWQHD = '3440x1440'
const FHD = '1920x1080'
const OUTPUT = 'HDMI-1'
const exec = promisify(childProcess.exec);
const {stdout,stderr} = await exec('xrandr')
const xrandrLines=stdout.split('\n')
const currentResLine = xrandrLines.find(line => line.includes('*'))
const currentRes = currentResLine.trim().split(' ')[0]
const newRes = currentRes === UWQHD ? FHD : UWQHD
const setResolutionCmd = mode => `xrandr --output ${OUTPUT} --mode ${mode}`
await exec(setResolutionCmd(newRes))
await exec("i3-msg reload")
await exec("i3-msg restart")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment