#!/bin/bash # by desgua - 2012/05/09 # # This script help to customize apps in selected viewports # # works with Compiz # check if we have the needed tools tool1=$(which xdotool) tool2=$(which calc) if [ -z $tool1 ]; then echo "Xdotool is needed, do you want to install it now? [Y/n]" read a if [[ $a == "Y" || $a == "y" || $a = "" ]]; then sudo apt-get install xdotool else echo "Exiting then..." exit 1 fi fi if [ -z $tool2 ]; then echo "Calc is needed, do you want to install it now? [Y/n]" read a if [[ $a == "Y" || $a == "y" || $a = "" ]]; then sudo apt-get install apcalc else echo "Exiting then..." exit 1 fi fi # viewport horizontal size vh=$(gconftool-2 -g /apps/compiz-1/general/screen0/options/outputs | sed 's/\[//' | sed 's/x.*//') # viewport vertical size vv=$(gconftool-2 -g /apps/compiz-1/general/screen0/options/outputs | sed 's/.*x//' | sed 's/+.*//') # numbers of horizontals viewports nh=$(gconftool-2 -g /apps/compiz-1/general/screen0/options/hsize) # numbers of verticals viewports nv=$(gconftool-2 -g /apps/compiz-1/general/screen0/options/vsize) # backup any previous script mv ~/.sessionconf ~/.sessionconf.bak # create the new sessionconf file touch ~/.sessionconf echo "#!/bin/bash # # generated by desgua's script sleep 5" > ~/.sessionconf chmod +x ~/.sessionconf clear # Info echo "I will help to customize your session. " echo echo "The size of your viewport is: "$vh"x"$vv echo echo "And you have "$nh" horizontals viewports and "$nv" verticals viewports. " echo # Select Viewport function selvvp { read -p "Lets select a viewport to configure. Please type the horizontal number of the viewport: " ah if [[ "$ah" -gt "$nh" || "$ah" -lt "1" ]]; then echo echo "Horizontal viewport not found. Please try again." selvvp fi } function selhvp { read -p " Please type the vertical number of the viewport: " av if [[ "$av" -gt "$nv" || "$av" -lt "1" ]]; then echo echo "Vertical viewport not found. Please try again." selhvp fi apvp } # Select App function apvp { echo " Please select the app you need at" $ah "x" $av ": " read a aa=$(which $a) if [[ -z $aa ]]; then echo "App not found, please try again" apvp else echo "Got it." shv=$(calc $ah*$vh-1) svv=$(calc $av*$vv-1) echo "xdotool set_desktop_viewport "$shv $svv >> ~/.sessionconf echo $a "&" >> ~/.sessionconf echo "sleep 1" >> ~/.sessionconf echo echo "Done!" read -n 1 -p "Configure another app? (Y/n)" a if [[ $a == "Y" || $a == "y" || $a = "" ]]; then selvvp selhvp else pt=$(xdg-user-dir HOME) ppt=$(echo $pt/.sessionconf) echo echo echo "Adding the script to startup applications" echo '[Desktop Entry] Type=Application' > ~/.config/autostart/sessionconf.desktop echo 'Exec='$ppt >> ~/.config/autostart/sessionconf.desktop echo 'Hidden=false NoDisplay=false X-GNOME-Autostart-enabled=true Name=Custumized script Comment=To launch apps in viewports' >> ~/.config/autostart/sessionconf.desktop echo "Exiting now. Hope you enjoyed" exit 0 fi fi } selvvp selhvp exit 0