Mercurial > hg > config
changeset 129:83bc1e6e5b54
part of a dream realized
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Fri, 18 Mar 2011 11:33:56 -0700 |
parents | 57069bd1a46a |
children | c61997cf17b0 |
files | .fluxbox/keys python/window_path.py python/window_title.py python/window_title.pyc |
diffstat | 4 files changed, 53 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/.fluxbox/keys Mon Mar 14 09:34:26 2011 -0700 +++ b/.fluxbox/keys Fri Mar 18 11:33:56 2011 -0700 @@ -47,6 +47,7 @@ F11 :Fullscreen # commands +Control Mod1 a :ExecCommand xclip -o | window_path.py | xclip -i Control Mod1 b :ExecCommand sleep 1; xset dpms force off # blank screen Control Mod1 c :ExecCommand xterm -geometry 21x9 -T "`date +'%b %-d'`" -e 'cal; sleep 10' # calender Control Mod1 d :ExecCommand date | xclip -i # put now's date on the X clipboard
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/window_path.py Fri Mar 18 11:33:56 2011 -0700 @@ -0,0 +1,17 @@ +#!/usr/bin/env python + +import os +import subprocess +import sys +import window_title + +def main(filename): + title = window_title.active_window_title() + path = os.path.expanduser(title) + if not os.path.exists(path): + return + path = os.path.abspath(path) + return os.path.join(path, filename) + +if __name__ == '__main__': + print main(sys.stdin.read().strip())
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/python/window_title.py Fri Mar 18 11:33:56 2011 -0700 @@ -0,0 +1,35 @@ +#!/usr/bin/env python + +""" +get the active window title +""" + +import re +import subprocess + +def active_window_id(): + process = subprocess.Popen(['xprop', '-root'], stdout=subprocess.PIPE) + stdout, stderr = process.communicate() + for line in stdout.splitlines(): + if '_NET_ACTIVE_WINDOW(WINDOW):' in line: + return line.rsplit(None, 1)[-1] + +def window_title(window_id): + process = subprocess.Popen(['xprop', '-id', window_id], stdout=subprocess.PIPE) + stdout, stderr = process.communicate() + for line in stdout.splitlines(): + match = re.match("WM_NAME\((?P<type>.+)\) = (?P<name>.+)", line) + if match: + type = match.group("type") + if type == "STRING" or type == "COMPOUND_TEXT": + return match.group("name").strip('"') + +def active_window_title(): + return window_title(active_window_id()) + +def main(): + title = active_window_title() + print title + +if __name__ == '__main__': + main()