Tips and Tricks About Computers, Web Development, Linux, the Internet and the Like
Posts tagged markedwontfix
Ubuntu Notifications (osd-notify) Sucks, notifications-daemon Rocks – Exploiting the Goodness with Compiz
Jun 25th
Posted by Tyler Mulligan in Compiz
Introduction
The long name for this blog used to be “Tyler Mulligan’s Tips and Tricks for Increasing your Efficiency“. I love finding ways to increase my efficiency and let computers do the work while I focus on more interests aspects of what the computer is providing me with. When I recognize an issue, I find a way to cut out time by streamlining the process for the most accurate repetition, like any programmer would/should/could.
I noticed myself taking a lot of screenshots with compiz’ built in screenshot tool (I can hold a hotkey and drag a box to take newspaper style clippings). This is very fast and simple, I highly recommend enabling this option and getting used to it. However, I don’t care much for clicking around on clunky websites to upload images.
This is where my adventure starts… when I find out a very useful feature was deprecated and not replaced in Ubuntu. I don’t use the new notification area, it has too much I don’t need, I never liked the behavior of these new osd-notify notifications which I found out now are even more worthless (sorry team).
Using Sane Notifications in Ubuntu
After reinstalling the GNOME default notifications system in Ubuntu I was able to use SANE notifications that actually… KICK ASS! I don’t understand how osd-notify is better than these which even comes with it’s own notification properties panel. Maybe it’s an under the hood thing…
Regardless, there is no doubt in my mind that notifications that you hover, can still slightly see but click through but cannot perform any actions, even a close, are just plan stupid and annoying..

Screenshot of the script I ended up writing using the “better” notification system to ask me if I want to upload the screenshot I just took to the server.
Linking the notifications
I linked the notifications the following way:

Python Script for Notification that Prompts for File Upload to Server
Knowing diddly squat about Python, I chugged forward with my classic notification popups that allow for interaction as it had the most activity around it and some examples available in /usr/share/doc/python-notify/examples/
I ended coming up with the following script thanks to some help from a few people in #python on irc.freenode.org
This is outside of the scope of this blogpost but this script assumes you have setup passwordless ssh to your server.
#!/usr/bin/env python
#
# Title: Notification 'scp' Option
# Author: Tyler Mulligan (tyler@detrition.net)
# Date: 06/25/2010
# Description:
# Used in combination with an event, such as an action or cron
# the latest file from a folder will be scped to your server and will copy
# the http location of the that file to your clipboard
#
# Orginally developed to be piped to from compiz screenshot tool
#
#
# The MIT License
#
# Copyright (c) 2010 Tyler Mulligan
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE
#
import pygtk
pygtk.require('2.0')
import gtk
import pynotify
import sys
import os
import subprocess
user = "user"
host = "server.com"
lfolder = "/home/user/screenshots/"
hfolder = "/home/remote_user/screenshots/"
httplink = "http://"+host+"/screenshots/"
timeout = 5000
# Set position
display = gtk.gdk.display_get_default()
screen = display.get_default_screen()
x = screen.get_width() - 1
y = screen.get_height() - 1
#x = 1919
#y = 12
def upload_cb(n, action):
assert action == "upload"
start = os.path.abspath(lfolder)
f = max([(os.path.getmtime(os.path.join(start,x)),x)
for x in os.listdir(start)])[1]
# setup URL in clipboard
clipboard = gtk.clipboard_get()
clipboard.set_text(httplink + f)
# make our data available to other applications
clipboard.store()
os.system('scp "%s" "%s@%s:%s"' % (lfolder + f, user, host, hfolder) ).wait()
n.close()
gtk.main_quit()
def ignore_cb(n, action):
assert action == "ignore"
n.close()
gtk.main_quit()
if __name__ == '__main__':
if not pynotify.init("Notifier 'scp' Option"):
sys.exit(1)
# Setup Popup
n = pynotify.Notification("Upload to Server?")
n.set_urgency(pynotify.URGENCY_NORMAL)
n.set_timeout(timeout)
n.set_category("device")
n.add_action("upload", "Yes, Upload", upload_cb)
n.add_action("ignore", "Ignore", ignore_cb)
# Set position
n.set_hint("x", x)
n.set_hint("y", y)
if not n.show():
print "Failed to send notification"
sys.exit(1)
gtk.main()
edit: I updated the script with some position information — I love that I can put the notifications ANYWHERE on my screen. I also variablized the timeout.
edit 2: Here is a video of my improved script in action — I’ll post the source later
http://interwebninja.com/videos/compiz-screenshot-piped-to-notification-daemon-for-upload.ogv
Going Beyond
The Compiz example is just something that server my immediate needs. The possibilities are however endless. You can for example, link this script to a cron job asking you if you want to sync some other sort of file. Or perhaps you’d like to add multiple buttons to give yourself a folder / server choice.
Happy hacking