keep a log of the active windows

while true; do (echo -n $(date +"%F %T"):\ ; xwininfo -id $(xprop -root|grep "ACTIVE_WINDOW("|cut -d\ -f 5) | grep "Window id" | cut -d\" -f 2 ) >> logfile; sleep 60; done
This logs the titles of the active windows, thus you can monitor what you have done during which times. (it is not hard to also log the executable name, but then it is gets too long)
Sample Output
2015-09-24 00:58:24: Guake!
2015-09-24 00:59:24: Guake!
2015-09-24 00:60:25: Commands matching running program sorted by votes | commandlinefu.com 

What Others Think

Ooh, that's lovely. I'm going to put that into a cron job. If only there was some way to detecting whether the keyboard or mouse had been used (for detecting coffee time). Get thinking everyone :-) . As for the command, I'd make a few changes. I'm a fan of sed, so I'd swap the first grep-cut for: sed -n '/ACTIVE_WINDOW(/s/.* //p' Don't print: sed -n Find /ACTIVE_WINDOW( Search and replace everything up to the last space: s/.* // Print the result: p . Replacing the second grep-cut isn't as easy: sed -n '/"/s/.*"\(.*\)".*/\1/p' Find a line with quotes: /" Split the string into before, inside and after the quotes Printing only the middle (parenthesised in the sed regex). . If you were really desperate to save characters, you could also change while true; do ... sleep 60; done to while sleep 60; do ... done . Oh, I've just thought of something else. You've parenthesised the commands to group the output, but it isn't necessary. You can move the file redirection onto the while loop: while true; do ... done >> logfile . That gives us: while sleep 60;do echo -n $(date +"%F %T"):\ ;xwininfo -id $(xprop -root|sed -n '/ACTIVE_WINDOW(/s/.* //p')|sed -n '/"/s/.*"\(.*\)".*/\1/p';done>>logfile . Original command 173 characters, new command 153 :-)
flatcap · 353 weeks and 2 days ago
Or... Replace the second grep-cut with awk: awk -F\" '/"/{print $2}' Separate at quotes: -F\" Search for quotes: /"/ Print the second arg: {print $2} . while sleep 60;do echo -n $(date +"%F %T"):\ ;xwininfo -id $(xprop -root|sed -n '/WINDOW(/s/.* //p')|awk -F\" '/"/{print $2}';done>>logfile 139 characters.
flatcap · 353 weeks and 2 days ago
Your sed replacement for the first grep-cut does not print the correct window id. Not sure why.
BeniBela · 353 weeks and 1 day ago
Hmm, that's disappointing. It works for me. xprop -root | sed -n '/WINDOW(/p' | sed 's/$/<<</' _NET_ACTIVE_WINDOW(WINDOW): window id # 0x1e00006 One matching line with no whitespace after the window id . echo "_NET_ACTIVE_WINDOW(WINDOW): window id # 0x1e00006" | sed 's/.* //' 0x1e00006 . xprop -root | sed -n '/WINDOW(/s/.* //p' 0x1e00006 . What do you get for these three commands?
flatcap · 353 weeks and 1 day ago
Sorry, the output of the first command should read: _NET_ACTIVE_WINDOW(WINDOW): window id # 0x1e00006
flatcap · 353 weeks and 1 day ago
On my laptop there are two ids. Like: _NET_ACTIVE_WINDOW(WINDOW): window id # 0x1e00006, 0x03
BeniBela · 353 weeks and 1 day ago
Damn this site. There should be three less-than signs after the first command output, but they've been cleaned up. . xprop -root | sed -n '/WINDOW(/p' | sed 's/$/!!!/' _NET_ACTIVE_WINDOW(WINDOW): window id # 0x1e00006!!!
flatcap · 353 weeks and 1 day ago
That means your grep-cut results in: 0x1e00006, (ID-COMMA) Ah, which (I've just tested), xwininfo accepts.
flatcap · 353 weeks and 1 day ago
In fact xwininfo ignores everything after the id. So change the sed to strip up to the # xprop -root|sed -n '/WINDOW(/s/.*#//p' You'll get 0x1e00006, 0x03 Then this should work: xwininfo -id " 0x1e00006, 0x03" . Leading to my updated command: while sleep 60;do echo -n $(date +"%F %T"):\ ;xwininfo -id $(xprop -root|sed -n '/WINDOW(/s/.*#//p')|awk -F\" '/"/{print $2}';done>>logfile
flatcap · 353 weeks and 1 day ago
Nope My laptop is really strange. First, it has to be ACTIVE_WINDOW in the sed, because XFCE adds an XFCE_DESKTOP_WINDOW(WINDOW): window id # 0x1400003 to xprop Second, xwininfo is not ignoring the last number. This fails: xwininfo -id $( echo " 0x2c00020, 0x0" ) This works: xwininfo -id " 0x2c00020, 0x0"
BeniBela · 353 weeks and 1 day ago
XFCE? Ah, ok. My WINDOW shortening was an optimisation too far. I can explain the xwininfo bit. After a little testing, I see: printf ">>%s<<\n" "0x1e00006, 0x123" >>0x1e00006, 0x123 One argument given to xwininfo . printf ">>%s<<\n" $(echo "0x1e00006, 0x123") >>0x1e00006, >>0x123 two arguments given to xwininfo . printf ">>%s<<\n" "$(echo "0x1e00006, 0x123")" >>0x1e00006, 0x123 One argument again. I should have spotted that. . That means if I quote the xprop clause, xwininfo gets one parameter and everybody's happy. Give this a try (if you're not bored yet): while sleep 60;do echo -n $(date +"%F %T"):\ ;xwininfo -id "$(xprop -root|sed -n '/ACTIVE_WINDOW(/s/.*#//p')"|awk -F\" '/"/{print $2}';done>>logfile
flatcap · 353 weeks and 1 day ago
Cool, it works Now you can simplify this: while sleep 60;do info=$(xwininfo -all -id "$(xprop -root|sed -n '/ACTIVE_WINDOW(/s/.*#//p')"); echo $(date +"%F %T"): $(ps -o %a p$(sed -n '/Process id:/s/[^0-9]//gp'<<<"$info") | tail -1) \"$(awk -F\" '/"/{print $2}' <<<"$info")\"; done>>logfile
BeniBela · 353 weeks ago
Hurrah! It works. . As for the new command. I like your combined echo X $(Y) $(Z) I've tidied it a little. . First, the sed for the Process ID will fail if the hostname has a digit in it. I've replaced it with awk: awk '/Process id:/{print $3}' <<< "$info" . Next ps has an 'h' arg to drop the head, meaning we can get rid of tail. Also, my version of ps doesn't need the letter 'p' before the pid. ps h -o %a $(awk ...) . That's about all I can do, for now. I had some crazy ideas about using tee and >(...) redirections, but I need to do some work. (I may investigate them tonight). . while sleep 60; do info=$(xwininfo -all -id "$(xprop -root|sed -n '/ACTIVE_WINDOW(/s/.*#//p')");echo $(date +"%F %T"): $(ps h -o %a $(awk '/Process id:/{print $3}'<<<"$info")) \"$(awk -F\" '/"/{print $2}'<<<"$info")\";done . I've created a couple of Gists: An expanded version of the command: https://gist.github.com/flatcap/ef17a54626092deeb684 . A program (idletime.c) to measure inactivity, to turn your commands into an automatic timesheet tool: https://gist.github.com/flatcap/ac70d95d9fa95a7f951f
flatcap · 353 weeks ago
any new recent updates with the forum?? https://boudoirphotographyspokane.com
Killersmile · 65 weeks and 3 days ago
where to get shrooms dried mushrooms african pyramid mushroom african transkei mushroom albino penis envy b+ mushrooms blue meanies mushroom brazilian magic mushroom burmese mushroom golden teacher mushroom ko samui super strain malabar coast martinique mexican mushroom mushroom british columbia super thai mushroom nepalese chitwan mushroom penis envy texas penis envy 6 texas yellow caps vietnamese white jedi mind fuck tri coloured ecuadorian mushroom magic mushsroom edibles mexican cubensis psychedelic chocolate bar where to get shrooms dried mushrooms african pyramid mushroom african transkei mushroom albino penis envy b+ mushrooms blue meanies mushroom brazilian magic mushroom burmese mushroom golden teacher mushroom ko samui super strain malabar coast martinique mexican mushroom mushroom british columbia super thai mushroom nepalese chitwan mushroom penis envy texas penis envy 6 texas yellow caps vietnamese white jedi mind fuck tri coloured ecuadorian mushroom magic mushsroom edibles mexican cubensis psychedelic chocolate bar midnight mint psychedelic chocolate bar origin mango psilo gummies 0.25g-1g origin strawberry psilo gummies 0.25g-1g penis envy psychedelic chocolate bar psilocybin cube gummies vegan dark chocolate psychedelic chocolate bar microdoses brain capsules 50mg-200mg chill capsules 50mg-200mg clarity capsules 50mg-200mg health capsules 50mg-200mg love capsules 50mg-200mg mood capsules 50mg-200mg pure capsules 50mg-200mg social capsules 30 pack 350mg social capsules 5 pack 350mg buy weed online without medical card marijuana flowers types of concentrates cannabis cartridges buy edibles online legal marijuana shatter cannabis wax marijuana hash buy psychedelic online tinctures for anxiety cannabis seeds bank weed smoker accessories birthday cake kush acdc strain ace killer og strain ak 47 strain alaskan thunder fuck alien kush strain ambrosia kush strain atomik moon rocks cbd 40.57% atomik moon rocks diamond 58.77% banana og strain bc big bud strain birthday cake kush blue cheese strain blue dream og kush blue moonrock kush blue rhino strain blueberry kush strain bruce banner strain cannabis trim cherry pie strain cannatonic strain citrix strain dark star kush durban poison strain eleven roses strain g13 haze strain gelato strain girl scout cookies flavors girl scout cookies online granddad purple strain grape nana weed strains grape pie strain green crack strain guava kush strain hawaiian skunk jack herer strain mendo breath weed mighty mango mr nice guy weed blue mystic strain northern lights strain northern lights moon rock platinum og kush gas og strain pink og kush platinum hawaiian strain pootie tang strain purple mimosa strain purple white widow strain smart buds sour diesel weed strain sour moonrock strain space monkey tins strawberry banana weed sun rocks super citrus haze strain super silver haze wedding cake strain exotic white widows strain zombie kush strain all natural pistachio crunch apple fritter vape cartridge aura edibles gummy-candy banana og cartridge birthday cake dank vape pen cartridg biscotti vape cartridge blackberry kush cartridge bliss edibles 300mg thc blue dream cartridge 180mlg berry blue raspberry 500mg-chocolate chip- cookies atomic wheelchair activated thc distillate strike gold blue dream shatter bubba kush shatter cbd dried organic ginger blueberry kush vape cartridges chemdawg shatter 50mg choco chunk cookies cookies and cream vape delta 8 thc capsules do-si-dos cartridges durban poison vape cartridge eds and bills edible candy bags forbidden fruit cartridge fruity pebbles cartridge gelato cartridge 1000mg girl scout cookies shatter girl scout cookies wax gorilla glue #4 wax gorilla glue cartridge gorilla glue shatter grand daddy purple kush wax gsc cartridge hardcore og cartridge jack herer cartridge jack herer wax jet fuel cartridge juicy melon cartridge khalifa kush shatter kosher kush cartridge labanese camel hash lemon berry cartridge
johnson20007 · 21 weeks and 4 days ago

What do you think?

Any thoughts on this command? Does it work on your machine? Can you do the same thing with only 14 characters?

You must be signed in to comment.

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.

Share Your Commands



Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for: