Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
FVDWLR - Firefox Virtual Desktop Window Location Restore-er Simple shell script to restore firefox window locations to their previous virtual desktop location.
# FVDWLR - Firefox Virtual Desktop Window Location Restore-er
#When Firefox restarts (crash/whatever), when the previous browsing session is restored, the virtual desktop that the window was running on is not also restored. If you're like me, and categorize browsing by windows and virtual desktops this is very annoying. (ie I have a Firefox window researching matlab on the same desktop that matlab is running on, and then on a different desktop I have Gmail/barnowl/irssi running.) This failure to restore desktops is thus quite annoying.
#This simple shell script fixes that by restarting Firefox within the shell script. It uses xprop and wmctrl to read and restore the virtual desktop location of windows after (forcibly) restarting Firefox.
#Note that I'm on Debian and so 'Firefox' is technically Iceweasel, so change the variable as needed
#Requires x11-utils and wmctrl packages:
# sudo apt-get install x11-utils wmctrl
#Patches welcome.
FF_PID=`pidof $FF_NAME`
WINDOWS=`wmctrl -l -p | grep $FF_PID| awk '{print $1}'`
declare -A WIN_LOC
declare -A WIN_NAME
for WIN in $WINDOWS; do
WIN_LOC[$WIN]=`xprop -id $WIN _NET_WM_DESKTOP | sed 's/^.*= //'`
WIN_NAME[$WIN]=`xprop -id $WIN _NET_WM_VISIBLE_NAME | sed -e 's/^.*= "//' -e 's/"$//'`
echo 'Press [enter] to kill firefox.'
read foo
sync # for good measure since we're just killing ff
kill $FF_PID
pidof $FF_NAME >/dev/null
while [ "$?" -eq "0" ]; do
echo 'firefox still running; sleeping'
sleep .8
pidof $FF_NAME >/dev/null
echo 'running firefox'
`$FF_NAME` 1>/dev/null 2>&1 &
echo 'Press [enter] to restore desktop positions'
echo "AFTER you've pressed 'restore' in firefox"
echo "And AFTER FF has had a chance to restore window names"
read foo
sleep 2
for WIN in $WINDOWS; do
wmctrl -r $NAME -t $LOC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment