You are not logged in.
Hi,
Does anyone know how to get Openbox to pop up a notification (dialog box) when a command you've just executed returns an error (or other output)? I've bound my sleep key to run suspend-to-ram, but I prefer to run that via a script that checks first to make sure I'm not in the middle of an offlineimap sync. Here is the script:
#!/bin/bash
SYNC=`pgrep imap`
if [ -z "$SYNC" ]; then
sudo pm-suspend
exit 0
else
echo "IMAP sync in progress, please wait"
exit 1
fi
And here is the relevant entry in my rc.xml:
<keybind key="XF86Sleep">
<action name="Execute">
<prompt>Are you sure you want to suspend to RAM?</prompt>
<command>~/scripts/suspend_w_mail_check</command>
</action>
</keybind>
Currently, the configuration above causes the script to echo its output to the console, but I'd prefer to have it as a notification within Openbox. I've seen the documentation for <openbox_pipe_menu>, but from what I can tell that's not quite what I'm after here. Does anyone know how (or if it's even possible) to either (i) have Openbox pop up a notification when the script exits with an error, or (ii) simply to pipe the output of the script to an Openbox dialog? I haven't found any documentation on "error" or "pipe output" options with Openbox actions, though of course I could be missing something obvious. Many thanks in advance for any thoughts.
Offline
Well, OpenBox is a WM so I think you are going to have to find another program for that. Since you are probably using some gtk too you probably could be gtk notifications to work without too much of a hassle. Someone can probably help you more with them though as I haven't had much experience with them.
As for pm-suspend, you could just use a dbus call, and then you won't have to configure sudo to have to accept pm-suspend as user. Here's the script based off a script that I got from simongmzlj that does a dbus-call to shutdown, restart, and suspend:
#!/bin/bash
# power - power management task as regular user
# Program name from it's filename
prog=${0##*/}
# Text color variables
txtund=$(tput sgr 0 1) # Underline
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldblu=${txtbld}$(tput setaf 4) # blue
bldwht=${txtbld}$(tput setaf 7) # white
txtrst=$(tput sgr0) # Reset
info=${bldwht}*${txtrst} # Feedback
pass=${bldblu}*${txtrst}
warn=${bldred}!${txtrst}
# Display usage if full argument isn't given
if [[ -z "$@" ]]; then
echo " $prog <shutdown|restart|suspend|hibernate>"
exit
fi
case $1 in
shutdown )
echo "$info Shutting down..."
dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Shutdown > /dev/null
;;
restart )
echo "$info Restarting"
dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Reboot > /dev/null
;;
suspend )
echo "$info Suspending to ram"
dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Suspend \
int32:0 > /dev/null
;;
hibernate )
echo "$info Suspending to disk"
dbus-send --system --print-reply --dest=org.freedesktop.Hal \
/org/freedesktop/Hal/devices/computer \
org.freedesktop.Hal.Device.SystemPowerManagement.Hibernate > /dev/null
;;
* )
echo " $prog <shutdown|restart|suspend|hibernate>"
esac
Last edited by Gen2ly (2009-12-15 17:19:09)
Setting Up a Scripting Environment | Proud donor to wikipedia - link
Offline
Maybe take a look at dialog : http://www.archlinux.org/packages/core/i686/dialog/
EDIT
Or maybe xdialog, gtkdialog or zenity.
Last edited by marxav (2009-12-15 17:31:19)
Offline
Thanks for the quick replies. After thinking about it a bit more, maybe this solution is more complicated than it needs to be. I think I would be happy if the suspend script just waited for the offlineimap sync to finish. So, altering the script as follows should do what I need (will check when I get home):
#!/bin/bash
SYNC=`pgrep offlineimap`
if [ -z "$SYNC" ]; then
sudo pm-suspend
else
wait $SYNC
sudo pm-suspend
fi
Edit: reading around a bit more, it seems like this might not work, since offlineimap's process (run by cron) is not a child of the suspend script here. Anybody know how to wait for a non-child process?
Edit #2: One work-around would be to use "sleep" to have it just wait 5 seconds, and then put that in a recursive function in case it needs more time:
#!/bin/bash
function go_to_sleep {
SYNC=`pgrep offlineimap`
if [ -z "$SYNC" ]; then
sudo pm-suspend
else
sleep 5
go_to_sleep
fi
}
go_to_sleep
Last edited by moose jaw (2009-12-15 18:33:10)
Offline
Maybe take a look at dialog : http://www.archlinux.org/packages/core/i686/dialog/
EDIT
Or maybe xdialog, gtkdialog or zenity.
Thanks for the tip here. I've just been playing around with zenity and it's incredibly easy.
Offline
If you still want notifications you can look at zenity, notify-send, or dzen2
The day Microsoft makes a product that doesn't suck, is the day they make a vacuum cleaner.
--------------------------------------------------------------------------------------------------------------
But if they tell you that I've lost my mind, maybe it's not gone just a little hard to find...
Offline