public
Created

FVDWLR - Firefox Virtual Desktop Window Location Restore-er Simple shell script to restore firefox window locations to their previous virtual desktop location.

  • Download Gist
restart-ff.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
#!/bin/bash
# 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_NAME='iceweasel'
 
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/"$//'`
done;
 
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
done;
 
echo 'running firefox'
`$FF_NAME` 1>/dev/null 2>&1 &
disown
 
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
NAME=${WIN_NAME[$WIN]}
LOC=${WIN_LOC[$WIN]}
#echo $NAME - DESKTOP $LOC
wmctrl -r $NAME -t $LOC
done;

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.