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.

xdotool search --onlyvisible --class "Chrome" windowfocus key 'ctrl+r'

See screenshot for an example how to register a global shortcut in Linux Mint.

Extended version:

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


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"

###Global Shortcut on Linux Mint