85f33de61112165e739bba2fbad3acc2acd23afc
[pandora-libraries.git] / testdata / scripts / op_menu.sh
1 #!/bin/bash
2 #actions done when the menu button is pressed
3 #only argument is the time the button was pressed in  seconds
4
5 if [ "$1" -ge "1" ]; then #button was pressed 3 sec or longer, show list of apps to kill instead of launcher
6   killist=y
7 fi
8
9 xpid=$(pidof xfce4-session)
10 if [ $xpid ]; then
11   echo "xfce4 is running"
12   xfceuser=$(ps u -C xfce4-session | tail -n1 | awk '{print $1}')
13   if [ $killist ]; then
14     echo "displaying kill list"
15     pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*-\(.*\)(\([0-9]\+\))/\2\n \1/p' | su -c 'DISPLAY=:0.0 zenity --list --multiple --column "pid" --column "name" --title "kill" --text "which apps should be killed"' - $xfceuser | sed 's/|/\n/')
16     for PID in $pidlist
17     do
18       kill -9 $PID
19     done
20   else
21     echo "starting appfinder"
22     # invoke the appfinder; nice app, but it takes a few seconds to come up
23     #su -c 'DISPLAY=:0.0 xfce4-appfinder' - $xfceuser
24     # invoke the bottom-left popup menu, for launching new apps, instead.
25     popuppid=$(pidof xfce4-popup-menu)
26     if [ $popuppid ]; then
27         echo "popup menu is already running"
28     else
29         su -c 'DISPLAY=:0.0 xfce4-popup-menu' - $xfceuser
30     fi
31   fi
32 else
33   echo "no x, killing all pnd aps so x or DE gets restarted"
34   pidlist=$(pstree -lpA | grep pnd_run.sh | sed -ne 's/.*(\([0-9]\+\))/\1/p')
35   for PID in $pidlist
36   do
37     kill -9 $PID
38   done
39 fi