To keep Firefox
minimized after closing its current tab (according to OP, see the comment) use the following commands in a terminal,
wmctrl -a firefox; xdotool key Ctrl+w; wmctrl -r firefox -b add,shaded
How it works
wmctrl -a firefox
Go to the window with a name containing 'firefox' in it
xdotool key Ctrl+w
Send the keystroke Ctrl+W to firefox which is the shortcut to close current tab in firefox.
wmctrl -r firefox -b add,shaded
Shade a window with a title that contains the word 'firefox' in it.
To know more about these see man xdotool
and man wmctrl
Alias for above command
You can make an alias for the above commands, say the alias name be cfct
( Close Firefox Current Tab) in ~/.bashrc
or better in ~/.bash_aliases
from a terminal as,
echo -e "\nalias cfct='wmctrl -a firefox; xdotool key Ctrl+w; wmctrl -r firefox -b add,shaded'" >> ~/.bash_aliases
. ~/.bash_aliases
If you don't have ~/.bash_aliases
replace ~/.bash_aliases
in the above commands with ~/.bashrc
Usage
open a terminal and enter
cfct
And it will close Firefox’s current tab instantaneously.
Note: You need to have wmctrl
and xdotool
installed in your system. To install them use,
sudo apt-get install wmctrl xdotool
Best Answer
There are few files who contain information about your sessions:
~/.mozilla/firefox/*.default/sessionstore-backups/recovery.js
which contains information about the current session, also contains information for the closed tabs and the previous session. Every 15 seconds Firefox creates a backup in this file. This file is not available when Firefox is closed.~/.mozilla/firefox/*.default/sessionstore.js
which contains information about the last session, when the Firefox browser is closed. This file is not available when Firefox is open.~/.mozilla/firefox/*.default/sessionstore-backups/previous.js
which contains information about the previous session.The analysis of the content of
recovery.js
shows that, for each tab, only the entries of the current URL contain stringattributes
.I. When Firefox is open:
1.A. If you want to get all URLs of the open tabs from the current session you can use this command:
* Please note that, you must
copy
/paste
all lines together into a terminal window and press Enter.Where:
cat $HOME/.mozilla/firefox/*.default/sessionstore-backups/recovery.js
will print the content of this file;sed "s/\\_closedTabs.*//"
will remove everything after the string_closedTabs
;sed "s/{/\n{/g" | \
will put a newline before each{
;egrep -o 'url.*attributes'
will filter only those parts of the lines who begin withurl
and end withattributes
. Without-o
option, the entire lines who contain the string will be filtered;cut -d\" -f3
will use"
as delimiter and will filter only the 3th column.In my case the output of the command is:
1.B. If you want to get the data for the current and for the previous session at once you could use this:
Where:
printf "\n# CurrentSession:\n";
will print# CurrentSession:
between two newlines;sed "s/\\_closedTabs/\{\"url\":\"# ClosedTabs:\"attributes/g"
will replace the string_closedTabs
with"url":"# ClosedTabs:"attributes
in the entire "file" (optiong
);sed "s/\\lastSessionState/\{\"url\":\"# LastSession:\"attributes/"
will replacelastSessionState
with"url":"# LastSession:"attributes
;sed "s/#/\n#/"
will put a newline before each#
.; echo
will add a blank line at the bottom.In my case the output of the command is:
2.A. If you want to get and the history, you could use:
In my case the output of the command is:
2.B. You can put a separator between the data for each tab:
In my case the output of the command is:
3. 1.B. and 2.B. together:
In my case the output of the command is:
II. When Firefox is closed:
When Firefox is closed, you can get the data for the last session. The approach is the same as explained above but instead of
recovery.js
you have to usesessionstore.js
(orprevious.js
):References:
man sed
;man egrep
;man cut
.