Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save ldiebold/953a9c126af7b60a30bb3e143f081fd6 to your computer and use it in GitHub Desktop.
Save ldiebold/953a9c126af7b60a30bb3e143f081fd6 to your computer and use it in GitHub Desktop.
Autokey Script Examples - Ubuntu
import subprocess
from subprocess import call
call(['google-chrome', 'https://cdn.materialdesignicons.com/4.7.95/'])
# Enter script code
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 winexists("google-chrome.Google-chrome"):
window.activate("google-chrome.Google-chrome", switchDesktop=True, matchClass=True)
else:
call(['google-chrome'])
# Enter script code
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 winexists("terminator.Terminator"):
window.activate("terminator.Terminator", switchDesktop=True, matchClass=True)
else:
call(['terminator', '-f', '--working-directory=/home/luke/code'])
# Enter script code
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 winexists("code.Code"):
window.activate("code.Code", switchDesktop=True, matchClass=True)
else:
call(['code'])
@prashantnirgun
Copy link

prashantnirgun commented May 30, 2021

If you encounter error in terminal script for Ubuntu (Gnome) try the following code

Enter script code

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 winexists("gnome-terminal-server.Gnome-terminal"):
window.activate("gnome-terminal-server.Gnome-terminal", switchDesktop=True, matchClass=True)
else:
call(['gnome-terminal', '--working-directory=/home/prashant/www'])

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment