Reload Chrome with xdotool

I found it to be rather tedious to switch between vim and my browser just to refresh it. Sure, there are some extensions to auto-reload on file change. But what happens if you’re change, say, the database?

Come on, it’s way cooler to do this on a keyboard shortcut.

#!/bin/bash
xdotool search --onlyvisible --class "Chrome" windowfocus key 'ctrl+r'

See screenshot for an example how to register a global shortcut in Linux Mint. ![[mint_keyboard_shortcut.png]]

Extended version:

I extended the script with a “switch the focus back to the last window”.

#!/bin/bash

focused_window_id=$(xdotool getwindowfocus)                             # remember current window
xdotool search --onlyvisible --class "Chrome" windowfocus key 'ctrl+r'  # send keystroke to refresh
xdotool windowactivate --sync $focused_window_id                        # switch window, sync to "wait"