Wishful Coding

Didn't you ever wish your
computer understood you?

Delicious bookmarks in Safari

I recently started using Delicious, and while they have a nice Firefox plugin and a bunch of bookmarklets, there is no easy way to get Delicious bookmarks into the Safari bookmarks bar. To get this done I wrote an Applescript with a little piece of Python to get Delicious bookmarks right in Safari. Here is how it looks: Delicious bookmarks in Safari Here is how to do it:
  1. Get the 2 scripts below and save them to a suitable location. You might want to place it in ~/Library/Scripts/Applications/Safari
  2. Edit the Applescript with the location of the Python script and the URL of your Delicious feed.
  3. Run the Applescript.
  4. Drag the resulting bookmarks folder or its content anywhere you want.
This will work for any RSS and maybe even Atom feed, you could even bookmark the feed of your Twitter account, for... *hum* easy access to individual tweets. This is the Python code:
import feedparser
print "<dl>"
for e in feedparser.parse( "http://feeds.delicious.com/v2/rss/pepijndevos" ).entries:
    print '<dt><a href="%s">%s</dt>' % (e.link, e.title.encode('ascii','ignore'))
print "</dl>"
Don't ask me why, but Safari needs broken html to import. Maybe because it is meant to import IE bookmarks? Anyway, this is the Applescript, the real thing:
do shell script "python ~/bin/feed2html.py > ~/Documents/delicious.html"
tell application "Safari"
        activate
        tell application "System Events"
                tell application process "Safari"
                        click menu item "Import Bookmarks…" of menu "File" of menu bar item "File" of menu bar 1
                        keystroke "g" using {shift down, command down}
                        keystroke "~/Documents/delicious.html"
                        keystroke return
                        keystroke return
                end tell
        end tell
end tell

PyMouse 1.0: Mouse control and events on Python

Since the first release of PyMouse I received a lot of feature requests. A list of all requests ordered by quantity:
  1. Receive mouse events
  2. Keyboard support
Digging around in platform specific APIs is not my favorite hobby, but when Aldo came to me with a good start for the Unix code, and copyrights send me some Windows code, I could do nothing but finish my Mac code and adapt everything to a common API. I'm also very grateful for the help from mailing list members of PyObjC and Python Xlib. Without their help I'd probably have to reverse the current version number. Keyboard support is not yet there, and I do not currently have time to write it. But I wrote down everything I know about the APIs I worked with on the PyMouse wiki, so it shouldn't be to hard to figure out for anyone willing to do it.

Download PyMouse

Good looking X11 apps on Mac

A while back I discovered that Pidgin is now available for Mac. The problem is that it is still a GTK app. For Mac users that means it runs in X11. It has always bothered me that all X11 applications you run on Mac look so extremely ugly. When I used Ubuntu a few years back I discovered mac4lin, a funny project that intends to make a Mac theme for Gnome. Ironically, since Gnome is based on GTK you can run mac4lin on the system it intends to emulate, which would give your GTK apps a nice Mac look. Let's see how... For this example I'm also going to install Pidgin, to show you how it looks. First, however we need to get a bunch of software. You need to have MacPorts installed for this to work.
  1. First we need to get GTK without X11. You can leave of the variants if the build fails to get the X11 version.
    sudo port install gtk2 +quartz +no_x11
  2. Now we can get Pidgin, or any other GTK2 app.
    sudo port install pidgin +quartz +no_x11
  3. To be able to easily switch theme later we also need this little app.
    sudo port install gtk2-chtheme
  4. Now download and extract the latest version of mac4lin from their website.
  5. Extract Mac4Lin_GTK_Aqua_v1.0.tar.gz in the GTK folder to /opt/local/share/themes/ (You'll need to authenticate)
  6. Run /opt/local/bin/gtk2-chtheme, select the newly installed theme.
  7. Click the font button and set it to Lucida Grande at 10pt, done!
  8. Run /opt/local/bin/pidgin to see the effect.
Before: Good looking X11 apps on Mac After: Good looking X11 apps on Mac Keyboard shortcuts: You might also want to use this hint to enable the CMD key for keyboard shortcuts. Sound: By default Pidgin uses you 'system beep' to notify you, solution:
sudo port install qtplay
Good looking X11 apps on Mac