Skip to content

Instantly share code, notes, and snippets.

@unhammer
Created February 28, 2019 13:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unhammer/645c02a7bc32dfbb54e1d07b1691ef8f to your computer and use it in GitHub Desktop.
Save unhammer/645c02a7bc32dfbb54e1d07b1691ef8f to your computer and use it in GitHub Desktop.
Run a program with focus_new set to on, then turn focus_new off again
#!/bin/bash
# Usage:
# chmod +x with-focus
# ./with-focus CMD ARG1 ARG2
# e.g.
# ./with-focus xfce4-terminal
# ./with-focus mousepad file.txt
# When this script exits, turn focus_new back to false
trap 'xfconf-query -c xfwm4 -p /general/focus_new -s false' EXIT
curwindow=$(xprop -root _NET_ACTIVE_WINDOW)
# Temporarily set focus_new true:
xfconf-query -c xfwm4 -p /general/focus_new -s true
# Run whatever program was given, in the background so we can exit and it will
# keep going:
"$@" & disown
# Keep this script running until the current window id changes (new window has
# focus).
while [[ "${curwindow}" = "$(xprop -root _NET_ACTIVE_WINDOW)" ]]; do
sleep 0.3
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment