Created
November 14, 2012 14:15
-
-
Save narusemotoki/4072339 to your computer and use it in GitHub Desktop.
任意のアプリケーションを最前面に移動したり,最小化するプログラム
This file contains hidden or 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/env python | |
# -*- coding: utf-8 -*- | |
from subprocess import PIPE, Popen | |
import os | |
import sys | |
def get_current_window_name(): | |
for i in Popen(['xprop', '-root'], stdout=PIPE).stdout: | |
if '_NET_ACTIVE_WINDOW(WINDOW):' in i: | |
for j in Popen(['xprop', '-id', i.split()[4]], stdout=PIPE).stdout: | |
if 'WM_ICON_NAME(STRING)' in j: | |
return j.split()[2][1:][:-1] | |
def toggle_foreground(app_name): | |
app = get_current_window_name() | |
if not app or not 0 is app.find(app_name): | |
os.system('wmctrl -a ' + app_name) | |
else: | |
os.system('xwit -iconify -names ' + app_name) | |
if __name__ == '__main__': | |
if 2 > len(sys.argv): | |
print(u'最前面,最小化の対象にしたいアプリケーションの名前を与えてください.') | |
else: | |
toggle_foreground(sys.argv[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment