question selection specific firefox tabs

186 views
Skip to first unread message

Jeroen Ruijter

unread,
Feb 3, 2015, 7:56:26 AM2/3/15
to xdotoo...@googlegroups.com
I found out about Xdotool this weekend and I like it a lot.
Till now I've not been able to get a list of firefox windows so I cannot
close it by correct name.

For regulary backup I need to do a lot of downloads from within firefox.
I like to close the tabs that are "completed", they do show up as "New Tab"
but I cannot control them by this name.
Because a lot of tabs will result in firefox crashing I would like to close finished tabs automatically.

Is there a command for this?

Jeroen Ruijter

unread,
Feb 5, 2015, 1:15:50 PM2/5/15
to xdotoo...@googlegroups.com
Iḿ almost where I want to be, system only complaining about the if then else statement, can anyone help me out with this?

regards Jeroen Ruijter

#!/bin/bash
for i in {1..25}
    do

        wids=( $(xprop -root | grep '_NET_CLIENT_LIST.*(WINDOW)' | sed 's/^.*#//' | sed 's/,/\n/g' | sort -u ) )
        f=`for w in ${wids[@]}; do xprop -id $w | grep -P '^WM_NAME' | grep -i firefox ; done | awk -F "=" '{print $2}'`

        echo Active Mozilla Firefox Window Name is $f
        echo ""
        m="Mozilla Firefox"

    if [$f=$m];
        then
            echo "Ihis is a empty firefox tab"
            xdotool search "Mozilla Firefox" windowactivate --sync key --clearmodifiers ctrl+w
        else
            echo "This is not a empty firefox tab"
            xdotool search "Mozilla Firefox" windowactivate --sync key --clearmodifiers ctrl+Tab
    fi

done 


Op dinsdag 3 februari 2015 13:56:26 UTC+1 schreef Jeroen Ruijter:

Jeroen Ruijter

unread,
Feb 5, 2015, 3:29:57 PM2/5/15
to xdotoo...@googlegroups.com
What ever I do $f never seems to be equal to $m but echoing those values tells me that they are the same sometimes
so I expect to do something wrong with     if [ "$f" == "$m" ]; where I would expect "Mozilla Firefox" is the same as "Mozilla Firefox"

#!/bin/bash
for i in {1..2}

    do

        wids=( $(xprop -root | grep '_NET_CLIENT_LIST.*(WINDOW)' | sed 's/^.*#//' | sed 's/,/\n/g' | sort -u ) )
        f=`for w in ${wids[@]}; do xprop -id $w | grep -P '^WM_NAME' | grep -i firefox ; done | awk -F "=" '{print $2}'`

        echo Active Mozilla Firefox Window Name is $f
        echo ""
        m="\"Mozilla Firefox"\"
        n=`echo "${f}" | sed 's/"//g'`
    if [ "$f" == "$m" ];

        then
            echo "Ihis is a empty firefox tab"
            xdotool search "Mozilla Firefox" windowactivate --sync key --clearmodifiers ctrl+w
            sleep 1
            echo f $f
            echo m $m
            echo n $n

        else
            echo "This is not a empty firefox tab"
            xdotool search "Mozilla Firefox" windowactivate --sync key --clearmodifiers ctrl+Tab
            sleep 1
            echo f $f
            echo m $m
            echo n $n

    fi

done 

Op dinsdag 3 februari 2015 13:56:26 UTC+1 schreef Jeroen Ruijter:
I found out about Xdotool this weekend and I like it a lot.

Jeroen Ruijter

unread,
Feb 5, 2015, 4:03:50 PM2/5/15
to xdotoo...@googlegroups.com
I had to use if [[ "$f" = *$m"* ]] to make it work ;)


#!/bin/bash
for i in {1..2}
    do

        wids=( $(xprop -root | grep '_NET_CLIENT_LIST.*(WINDOW)' | sed 's/^.*#//' | sed 's/,/\n/g' | sort -u ) )
        f=`for w in ${wids[@]}; do xprop -id $w | grep -P '^WM_NAME' | grep -i firefox ; done | awk -F "=" '{print $2}'`

        echo Active Mozilla Firefox Window Name is $f
        echo ""
        m="\"Mozilla Firefox"\"
        n=`echo "${f}" | sed 's/"//g'`
    if [[ "$f" = *"$m"* ]];

        then
            echo "Ihis is a empty firefox tab"
            xdotool search "Mozilla Firefox" windowactivate --sync key --clearmodifiers ctrl+w
            sleep 1
            echo f $f
            echo m $m
            echo n $n
        else
            echo "This is not a empty firefox tab"
            xdotool search "Mozilla Firefox" windowactivate --sync key --clearmodifiers ctrl+Tab
            sleep 1
            echo f $f
            echo m $m
            echo n $n
    fi

done 



Op dinsdag 3 februari 2015 13:56:26 UTC+1 schreef Jeroen Ruijter:
I found out about Xdotool this weekend and I like it a lot.

Justin Chaschowy

unread,
Feb 5, 2015, 5:34:15 PM2/5/15
to xdotoo...@googlegroups.com
Nice problem solving, I was going to suggest looking for a firefox addon that accomplished the task of closing tabs

G.W. Haywood

unread,
Feb 5, 2015, 11:31:01 PM2/5/15
to Jeroen Ruijter, xdotoo...@googlegroups.com
Hi there,

On Thu, 5 Feb 2015, Jeroen Ruijter wrote:

> Iḿ almost where I want to be, system only complaining about the if then
> else statement, can anyone help me out with this?

It's 'elif' not 'else' in a shell script.

73,
Ged.

G.W. Haywood

unread,
Feb 5, 2015, 11:31:01 PM2/5/15
to Jeroen Ruijter, xdotoo...@googlegroups.com
Hi there,

On Tue, 3 Feb 2015, Jeroen Ruijter wrote:

> Because a lot of tabs will result in firefox crashing I would like to close
> finished tabs automatically.

You should fix your system. Firefox should not crash because you open
a lot of tabs. I routinely use many Firefox tabs and this has never
caused it to crash.

> Is there a command for this?

CTRL-W in the tab.

--

73,
Ged.
Reply all
Reply to author
Forward
0 new messages