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
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.
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.
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
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:
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 changewhile true; do ... sleep 60; donetowhile 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 :-)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>>logfile139 characters.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?xprop -root | sed -n '/WINDOW(/p' | sed 's/$/!!!/'_NET_ACTIVE_WINDOW(WINDOW): window id # 0x1e00006!!!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>>logfilexwininfo -id $( echo " 0x2c00020, 0x0" )This works:xwininfo -id " 0x2c00020, 0x0"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>>logfilewhile 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