A very simple list (with Alfred and GeekTool)

Things you’ll need: Alfred with Powerpack and GeekTool.

The premise is simple: maintain a simple list with Alfred, use GeekTool to show it on your desktop.

The Alfred part will be a Keyword → Run Script Workflow. The keyword I’m using is list, with an argument required.

list-01

For the script, I’m using PHP because that’s what I’m most comfortable with. The summary is thislist-02

  1. Get the list file
  2. Read the json
  3. Add/remove based on the query from alfred
  4. Write the json back to the file
// the file
$file = '/full/path/to/list.json';

// read it
$list = file_get_contents( $file );

// make it parseable
$list = json_decode( $list, true );

// the query from alfred
$q = "{query}";

// pop the first word off
$_q = explode( ' ', $q );
$command = array_shift( $_q );

switch( $command ) {
	case 'delete':
	case 'd':
		unset( $list[ implode( $_q ) ] );
	break;
	case 'reorder':
		$list = array_values( $list );
	break;
	case 'removeall':
		$list = array();
	break;
	default :
		$list[] = $q;
	break;
}

// back into flat json
$list = json_encode( $list );

// write it
fwrite( fopen( $file, 'w' ), $list );

I’ve also unchecked escaping for all but double quotes.

This enables a few basic subcommands.

  • > list add item Append something to the list
  • > list d {item-key} Remove something from the list
  • > list reorder Reset the keys
  • > list removeall Remove all items

alfred-list

Then the GeekTool part. Drag a new shell geeklet to your desktop, and add a script that can read and output the list. Again, I’m using PHP.

#!/usr/bin/php
<?php

$list = file_get_contents( '/Users/KLampert/Documents/list.json' );

if ( ! $list || '[]' == $list ) return;

$list = json_decode( $list, true );

$max = max( array_keys( $list ) );
$len = strlen( $max );

foreach ( $list as $k => $v ) {
	$i = str_pad( $k, $len, ' ', STR_PAD_LEFT );
	echo "$i. $v\n";
}

Mine refreshes every 5 seconds.

Very basic, which is what I need.

Oh, and don’t forget to change the paths!

Download: read-list.glet, List.alfredworkflow

Leave a Reply

Your email address will not be published. Required fields are marked *

%d bloggers like this: