Created
April 16, 2017 08:51
-
-
Save carlzulauf/90808fc8fe0b43fce3f28d9bf29aeb96 to your computer and use it in GitHub Desktop.
use wmctrl and gtk-launch to bring an existing window to the front or launch the app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
base_cmd = ARGV[0] | |
cmd_pattern = Regexp.new(base_cmd) | |
running = `wmctrl -lx`.lines.grep(cmd_pattern) | |
if running.any? | |
window_id = running.first.match(/0x[0-9a-f]{8}/)[0] | |
exec "wmctrl -ia #{window_id}" | |
else | |
puts "starting: #{ARGV.join(' ')}" | |
exec "gtk-launch", *ARGV | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment