| 1 | #!/bin/bash |
| 2 | # |
| 3 | # 01pidgin: suspend/wakeup pidgin |
| 4 | |
| 5 | purple_remote='/usr/bin/purple-remote'; |
| 6 | |
| 7 | purple_global_remote() { |
| 8 | for user in $(ps -o euser,comm -C dbus-daemon | tail -n +2 | cut -d ' ' -f 1 | grep -v '^dbus$'); do |
| 9 | command="$1"; |
| 10 | tempfile="/tmp/pidgin-last-status-$user"; |
| 11 | if [ "$command" == 'resume' ]; then |
| 12 | command='setstatus?status='$(cat "$tempfile"); |
| 13 | else |
| 14 | last_status=$(su "$user" -c "$purple_remote getstatus"); |
| 15 | echo -n "$last_status" > "$tempfile"; |
| 16 | echo "user $user will be resumed to: $last_status"; |
| 17 | fi; |
| 18 | su "$user" -c "$purple_remote $command"; |
| 19 | done; |
| 20 | } |
| 21 | |
| 22 | case "$1" in |
| 23 | hibernate|suspend) |
| 24 | purple_global_remote 'setstatus?status=offline'; |
| 25 | sleep 1; |
| 26 | ;; |
| 27 | thaw|resume) |
| 28 | purple_global_remote resume; |
| 29 | ;; |
| 30 | *) exit $NA |
| 31 | ;; |
| 32 | esac |