Skip to content

Instantly share code, notes, and snippets.

@ldiebold
Created September 28, 2020 01:28
Show Gist options
  • Save ldiebold/b594abe483dcbdf5e99fdae3c74484b0 to your computer and use it in GitHub Desktop.
Save ldiebold/b594abe483dcbdf5e99fdae3c74484b0 to your computer and use it in GitHub Desktop.
AutoHotkeys - Open to, or switch to application
# Example using google chrome
import subprocess
from subprocess import call
def winexists(target):
for line in subprocess.check_output(['wmctrl', '-l', '-x']).splitlines():
window_name = line.split(None, 3)[2].decode()
if window_name == target:
return True
return False
# If the window for google chrome exists, switch to it
if winexists("google-chrome.Google-chrome"):
window.activate("google-chrome.Google-chrome", switchDesktop=True, matchClass=True)
# Otherwise, open it!
else:
call(['google-chrome'])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment