Created
September 28, 2020 01:28
-
-
Save ldiebold/b594abe483dcbdf5e99fdae3c74484b0 to your computer and use it in GitHub Desktop.
AutoHotkeys - Open to, or switch to application
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
# 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