Wishful Coding

Didn't you ever wish your
computer understood you?

A better Trash for Mac

Different at least... I bothers me that the Mac Trash leaves hidden .Trash folders everywhere, including external drives. I wrote a few AppleScripts to move all Trash in one place and delete files completely. If you only want to remove trash from external drives, see my earlier post. This approach is still far from ideal, but it's interesting and it might inspire someone to do a better job than I did. The idea is to move files to a sparse image and delete that image when you need to empty the Trash. You can do this with Disk Utility and a bit of AppleScript.

A better Trash for Mac

To create the image, open Disk Utility in /Applications/Utilities, click New Image and create a Sparse Image.

A better Trash for MacI think it is nice to make the image a Stationary Pad, so you get a new Trash can every day for easier selective deletion. To do this, select the image and press CMD+i and select Stationary Pad. Now all that remains are the AppleScripts. Save those as Application Bundles named Trash and Delete respectively.
property image : POSIX file "/Users/pepijndevos/Trash/Trash.sparseimage" -- edit this
property mount : POSIX file "/Volumes/Trash" -- and this

tell application "Finder"
        if not (exists mount) then
                open image
                delay 5
        end if
        open mount
end tell

on open the_files
        tell application "Finder"
                if not (exists mount) then
                        open image
                        delay 5
                end if
                repeat with the_file in the_files
                        do shell script "mv -f " & quoted form of POSIX path of the_file & " " & quoted form of POSIX path of mount
                end repeat
        end tell
end open
on open the_files
        repeat with the_file in the_files
                do shell script "rm -rf " & quoted form of POSIX path of the_file
        end repeat
end open
A better Trash for MacNow drag these to the Dock for easy access to the Trash and Delete functions. You can just drag files on them to trash or delete them. Another option of course is to have only the Delete script and a regular folder in your Dock, but that is not half as fun, is it?
Published on

Updating to Wordpress 3.0

I'm trying to upgrade this blog to WordPress 3.0. While I skipped 2.9.2 because it was only a minor fix, this time there are some cool new features, which I'm not going to tell about, use Google! This theme used the default comment template in WordPress 2.9, but unfortunately this has been removed or broken. To fix this, I had to use the comments.php from the new and shiny twentyten theme. I copied their comments.php over to my theme, but unfortunately this only made matter worse. It uses a few functions defined in functions.php. Rather than trying to copy those specific functions over to my functions.php, I just included theirs:
include(TEMPLATEPATH . "/../twentyten/functions.php");
Can you think of a more ugly solution? I'll fix it later. There might be more bugs to be discovered. Do you see anything out-of-order on this blog? Please leave a comment.

Wordpress RSS widget in a post/page

I'm currently writing a theme for a friend who is going to coach photographers. He wants to have a page that lists RSS feeds from all those photographers. One part of the puzzle is easily solved by using Yahoo! Pipes to combine those feeds, the other part isn't that easy to solve. WordPress comes with a standard RSS widget, but it's only a widget, not a shortcode. There are a bunch of plugins that either offer a RSS widget or turn feeds items into posts. What I did is write my own plugin in only 10 lines of actual code, utilizing the shortcode API and the built-in RSS widget.
  1. Save and upload the snippet below to your plugins folder
  2. Activate it in the WP admin
  3. Add the [rsstag] shortcode to your post or page
  4. Add the feed url like this: [rsstag url="http://pepijn.cqhosting.nl/feed/"]
  5. Save!
You can optionally add one or more of show_summary=1, show_date=1 or show_author=1 to add the respective meta-data to every entry.
php
/*
Plugin Name: Wordpress RSS shortcode
Plugin URI: http://pepijn.cqhosting.nl/2010/06/wordpress-rss-widget-in-a-post-page
Description: This plugin fetches an RSS feed as a shortcode
Author: Pepijn de Vos
Version: 1.0
Author URI: http://pepijn.cqhosting.nl
*/

function rsstag($atts) {
        $atts = shortcode_atts(array(
                'url' => get_bloginfo('rss2_url'),
                'show_author' => 0,
                'show_date' => 0,
                'show_summary' => 0
        ), $atts);
        //var_dump($atts);
        wp_widget_rss_output($atts['url'], $atts);
}
add_shortcode('rsstag', 'rsstag');
?>
I will upload this to WordPress.org soon.