Martin Ström

Google Email Uploader

For different reasons I have many different Google accounts and wanted to merge them all into one Google Apps for Domain account. I also wanted to upload email from the past years to that account.

I’ve tried before to move a lot of messages between Google/Gmail accounts by just dragging the messages from one IMAP account into another (using a regular IMAP client such as Thunderbird or Mail), but it never works for a lot of messages. Then I found out about the Google Email Uploader tool, and gave it a try.

My first attempt was to use the Mac version of Google’s Email Uploader and just upload all messages I had downloaded in my local OS X Mail setup. The upload was supposed to take around 18 hours and I tried twice but both times, the uploader seemed to get stuck on some message(s).

I downloaded the source for the app and tried to figure out if I could patch the app to make the work easier. But instead of digging through all code, I thought I should give the Windows version a try instead. It has been around for a longer time and therefore probably a bit more reliable.

So I set up Thunderbird in my Windows installation (running VMware Fusion), and downloaded all messages from my IMAP server, and then uploaded them using Google Email Uploader for Windows. Everything went smooth and took about 20 hours.

For the next batch I imported the messsages into Thunderbird for Mac and then used the uploader tool for Mac. This time it worked great (but was fewer messages).

So, lesson learned: Try to import the messages into Thunderbird if the uploader get stuck when uploading from If that doesn’t work, try the Windows version.

TextMate command to copy an txmt:// url to the current file

I’ve been using this TextMate command for many years to copy an URL to the current file and then paste into a bug tracker/todo list or something.

A better Mail-to-Things-ToDo script

Until now I’ve been creating todos in Things from Mail messages in OS X using the quick entry built into Things and the “autofill” feature. But I didn’t like that it, by default, created the todos in Things’ Inbox and that I had to manually select text in the mail message to get it as notes (which is important when using Things on your iPhone/iPad when the link back to the mail message doesn’t work).

Instead here’s an AppleScript which will take the selected message(s) and automatically create one task for each email in the “Next” focus in Things. It will then archive the mail messages and show a Growl notification. The todos in Things will get tagged with the “Reply” tag (which in my setup is a subtag of “Email”).

The script is a modified version of the one found here. I also put the script in an Automator action like described in the article so you can assign a shortcut key to it without including third party software.

QuickTip: Change Finder’s default folder

#protip: Change Finder’s default folder to one you often use (like ~/Projects or whatever) than a minute ago via Tweetie

Open Selected Folder or File in TextMate from Finder


Before upgrading to Snow Leopard I had a QuickSilver trigger (⌃⌥⌘M) to open the currently selected file(s) or folder(s) in TextMate. It was setup as a QuickSilver trigger using the Proxy Object “Finder Selection”. Too bad it doesn’t work for me in the later QuickSilver versions and/or Snow Leopard.

I missed this trigger so I made a 10.6 Service to accomplish the same task:


  1. Run Automator and select “Service” from the template chooser.
  2. Select “Files and Folders” from “Finder”
  3. Find the “Open Finder Items” action from the left pane and select TextMate as the application.
  4. Save the service in ~/Library/Services. I called mine “Open With TextMate”

Keyboard Preferences

To run the service from the keyboard, run “System Preferences” and select “Keyboard”, then select “Services” in the left menu and locate the “Open With TextMate” service on the right side. Add a keyboard shortcut (I choose the same as I’m used to, ⌃⌥⌘M).

Automatically iChat complete Transmission downloads

Lets say you have an extra computer at home which can be used to download Linux distros using Transmission on Mac OS X. Here’s how you can let the computer iChat you when a download is complete.

  1. Sign up for a new iChat screen name and add your normal user as a buddy.
  2. In Transmission, open Preferences → Transfers and set the folder for incomplete files to something different than the “Default download location”.
  3. Start Automator (in /Applications) and create a new workflow
  4. Add the “Run AppleScript” action and paste in this code (replace YOURBUDDY with the scree name of your own iChat account:
  5. Save as a plugin and choose “Folder action” in the “Save As” dialog. Select the folder you setup Transmission to use as the “Default download location”.
  6. Done! The script should now send you an iChat message whenever a new file is added to the folder.

I created this setup a pretty long time ago and still use it, but these days together with a Growl notification plugin that also twitters me when the download is complete.

Screencapture in Mac OS X from a SSH session or launchd jobs

If you’d ever need to use the screencapture command from a scheduled job (like launchd in OS X) or from a SSH session, you might find out that it doesn’t allow you to do that since you’re not the logged in user.

To work around that, run the scheduled jobs as root and exec screencapture like this instead:

MissingDrawer TextMate Plugin for Mac OS X 10.6 Snow Leopard

I really like the MissingDrawer plugin for TextMate but it stopped working for me after upgrading to Snow Leopard. I recompiled it for 10.6 and now it works again.

Get the updated versions here (one with blue background and one with the white default).


Seems like the plugin doesn’t work very good after all. It makes TextMate stop responding to modifier keys (command, shift etc) so my recompiled version isn’t very helpful right now. I’ll investigate and try to fix it.

RailsTerm 0.3

Terminal + RailsTerm

Just a quick note that RailsTerm, my AppleScript to automatically open the tabs (in OS X 10.5 Terminal) needed for Rails development), is bumped to version 0.3.

Since I use Passenger (mod_rails) and Passenger.prefpane for my local development the script will now auto detect the virtual hosts available on your system (in /etc/apache2/passenger_pane_vhosts/*.vhost.conf). I use the script daily and is a real time-saver for me.

RailsTerm or browse source is on GitHub.

Clean up your Spotlight search results


By default, Spotlight will index all your mail messages and attachments, even those in your Trash and Spam folders. To exclude these folders from the Spotlight results you can add the folders to the “Privacy” section of the “Spotlight” pane in “System Preferences”.

I’m using IMAP on Gmail so your path may be a little different if you’re on another setup. The paths I choose to exclude are

~/Library/Mail/[Gmail]/All Mail.imapmbox/Attachments

You might not want to use the last one if you tend to keep attachments in the mail message but I usually save the important ones to a real folder.

My Terminal Setup for Rails Development

I’m quite happy with my setup right now for the Rails projects I’m working on and wanted to share the bits and pieces I use.

First, I found a SIMB plugin for Terminal that’ll show the tab’s title in the tab instead of the running process. I use the plugin with a simple title helper in my .bash_profile to set the title simply.

function title () {
  unset PROMPT_COMMAND # more on this later
  echo -ne "\e]0;$1\a"

# Usage:
# title 'my title'

Second, I use a technique I saw on how to automatically set the title to display the current working directory as title, but since I use the plugin and helper function above, I could simplify the PROMPT_COMMAND a bit:

function set_window_and_tab_title {
  local title="$1"
  [[ -z "$title" ]] && title="root"
  echo -ne "\e]0;${title}\a"

PROMPT_COMMAND='set_window_and_tab_title "${PWD##*/}"'

That’s why I unset PROMPT_COMMAND in my title function, so it won’t auto update when I choose to set it manually using the title function.

The last piece is an updated version of my old Rails Term-script for iTerm which has been updated (and improved) for the Terminal in Mac OS X Leopard instead of iTerm.

It will open the tabs I usually use when doing Rails development and set the title of each tab using the above mentioned functions. You need to enter you projects root directory and the projects you want to have easy access to. I’ve added some comments to the AS code to help you out.

Download a zipped version of the AppleScript. Just drag the script to the Script Editor (/Applications/Utilities) to edit it.

All source code for these scripts can also be viewed on Pastie. Let me know if you have any improvements.

iCal & iPhone syncing in Leopard

Looks like I’m not the only one having problems with my iCal to/from iPhone syncing.

After trying almost every possible solution I found in various forums and google, I finally came up with a fix that works for me. Like many others, I suspected the subscribed calendars were the problem and the iPhone synced fine after removing the subscriptions (including the built-in Birthdays calendar). But I have some subscribed calendars I want to have in iCal and found out that the cannot live in a group. I used to have a calendar group (File → New Calendar Group) for my “noisy” calendars so I could hide them easy with just one click. Looks like iCal/iPhone/Sync/OSX/whatever doesn’t like this and syncing stops working when using the group.

Doesn’t work:




Mac OS X 10.5.1 and Multi-Safari

Seems like Multi-Safari (at least 2.0.4) broke when upgrading to Mac OS X 10.5.1. I get this error:

“You cannot use the application ‘Safari 2.0.4′ with this version of Mac OS X.”

Luckily, I’ve found a workaround. Just launch Safari from the command line ( that is) and it should work for you:

/Applications/Safari\ &

OmniFocus to iPhone bookmark exporter

Since the iPhone lacks the possibility to export tasks from iCal I made hack/script to export all tasks from OmniFocus to a Safari bookmark and therefore be syncable with Safari.

Read more in the OmniGroup forums and/or download the latest version here.

Update: On request, here are some screenshots of how the todo list looks like:


AppleScript to open iTerm tabs for Rails development

Update: This script is ported (and improved) to work with OSX Leopards’

I never really liked iTerm because of slow redrawing, ugly text anti aliasing and not reflowing text when resizing the window.

After reading some interviews on a Rails site today and saw that a lot of people are using iTerm i wanted to give one more try (because I’d really like a tabbed terminal).

It has improved a lot the latest months and seems really usable now. To make Rails development easier, I hacked together a small AppleScript what will ask you for the path to the Rails directory you want to use and then open four new tabs with Server/Mongrel, Console, Autotest and the directory itself. I thought it could be useful for others as well so here you go:

Save as an .app and run from Quicksilver:

global rails_dir

tell application "iTerm"
    set rails_dir to the text returned of (display dialog ¬
        "Please Enter the Path to Your Rails Directory" default answer ¬
        "~/Projects/" as text)

    if (count of terminal) = 0 then make new terminal

    my open_tab("Server", "&& ./script/server")
    my open_tab("Console", "&& ./script/console")
    my open_tab("Autotest", "&& autotest")
    my open_tab("Rails Directory", "")
end tell

on open_tab(title, command)
    tell application "iTerm" to tell first terminal
        launch session "Default"
        tell last session
            write text "cd " & rails_dir & command
            set name to title
        end tell
    end tell
end run_command

TextMate Prototype & Scriptaculous Bundle

This the first version of a TextMate bundle for Prototype and JavaScript libraries. The language grammar is based on from Justin Palmers Prototype Bundle but the other commands/snippets are all new. Please let me know if you have any comments and/or improvements.

Download here

Update 2006-07-16

The bundle is now added to TextMates official svn repository.

AutoPair functionality using Cocoa KeyBindings

I’ve been using the application “AutoPairs” since it was mentioned on 43folders some time ago. Yesterday (via the Macromates TextMate blog) I found an article on the Cocoa Text System and realised I could recreate AutoPairs’ functionality by just using native Cococa Keybindings found in OSX.

Add these lines to your ~/Library/KeyBindings/DefaultKeyBinding.dict (create the file if it isn’t already there) and the commands will be available in every application started afterwords.

/* Recreate Auto pairs functionality */
"\\\"" = ( "insertText:", "\"\"", "moveBackward:" );
"("    = ( "insertText:", "()", "moveBackward:" );
"~("   = ( "insertText:", "{}", "moveBackward:" );
"~8"   = ( "insertText:", "[]", "moveBackward:" );
"<"    = ( "insertText:", "<>", "moveBackward:" );

When you type e.g ⇧2 for a double quote (as in swedish keyboard layout), it’ll automatically insert the ending quote as well and place the cursor between them. This will also work for “([{<”. Remember the shortcuts are for a swedish keymap so you might want to change that.

A real time saver when writing outside an editor without this functionality built-in (like TextMate).

Update 2006-08-07 Simplfied the commands based on Jacob Rus’ comment.

Autonamed dump/temp folder

To keep my desktop nice and clean I have a folder called “Dump” where I put temporary stuff like apps I want to try, PDF:s to read later that day or files I’m currently working with. But sometimes I forget to look inside that folder to find out what’s there so I wrote this Folder Action to let the folders name reflect the number of containing files/folders. (I know I could just enabled “Show item info” from Finders “View Options” but I don’t want to see all info for my hard drives and iPod)


Just create a folder on your desktop, name it something like “Dump (temp)” and attach this Folder Action to it (Folder Actions need to be located in ~/Library/Scripts/Folder Actions).

-- Set item count as folder name.scpt
on adding folder items to this_folder
    my update_name(this_folder)
end adding folder items to

on removing folder items from this_folder
    my update_name(this_folder)
end removing folder items from

on update_name(this_folder)
    set this_name to POSIX path of this_folder
    set sh_script to do shell script "P=\"" & (POSIX path of (path to me) as string) & "\";echo ${P/%.scpt/.sh}"
    set new_name to do shell script "\"" & sh_script & "\" \"" & this_name & "\""
    tell application "Finder" to set name of this_folder to new_name
end update_name

The script needs a shell script to work (since I don’t like working with AppleScript that much). It should be named exacly as the AppleScript but with an .sh extension instead of .scpt and put in the same directory. Remember to make it executable (chmod +x "Set item count as folder").

#!/usr/bin/env bash
# Set item count as folder

# Since the folder has a custom icon and therefore a `Icon?` file I
# decrease the item count by 1. Bad solution but works for now.
NUM_ITEMS=`bc <<< "$(ls "$1" | wc -l) - 1"`
if [[ $NUM_ITEMS == 0 ]]; then
elif [[ $NUM_ITEMS == 1 ]]; then
    ITEMS="$NUM_ITEMS item"
    ITEMS="$NUM_ITEMS items"
BASE=`ruby -e "puts %x(basename \"$1\").match(/(.+) \(/)"[1]`
echo "$BASE ($ITEMS)"

I first renamed the folder from the shell script but then Finder would visually move the folder one step down or left on the desktop for every update. Instead I just let the shell script generatr the new name and pass it back to the AppleScript that will rename the file as I want. usage

The other day, Oskar Karlin asked me how and when I use the OS X Terminal app instead of e.g. the Finder. I’m not by any means a hard core command line guy but ther are often and often situations where the Terminal is faster or/and easier to use for the specific thing.

Colhour as iChat picture 2.0

This is the second version of the Colhour as iChat picture I posted the other day. The biggest improvment is that it will show both the hours and the minutes.

There’re two versions of the script. The first one uses a Ruby script together with RMagick to create every image on the fly with the current time. But since it requires some installation of Ruby gems and other libraries, I decided to make a version with all 1440 images pregenerated (created with a small Ruby script of course) so you wont need to install the other libraries. The AppleScript still uses some Ruby, but it’s included in OS X, and should (at least) work on a basic OS X 10.4 Tiger installation. Let me know otherwise.

Instructions on how to set up a cron job to run the script every minute is in the previous post. Both the on-the-fly generated version (update-gen.scpt) and the pregenerated version (update-pregen.scpt) are included in the zip file.

iChat picture with Colhour

This is a small AppleScript to update your iChat picture from the Colhour system that I have created with Peter. From the beginning I wanted to update it every second, but since it used 60% – 80% CPU, I decided to go with an update rate of once a minute instead. So you’ll only be able to se the current minute from the iChat picture.

To install: Download and extract somewhere on your hard drive. Edit your crontab file manually or with an app like Cronnix to run the script every minute. It should look something like this:

*/1 *   *   *   *   YourUserName    osascript ~/path/to/update.scpt

I suppose I should do this in the “correct OS X Tiger” way by using launchd instead, but that’s for next time. As well as update it to show the the full date in different squares (without seconds due to CPU usage) like the one on

Source included.

Version 0.2

Added a check in the script to see if iChat is running or not, so it wouldn’t launch iChat every minute.

Pluxemburg upload script

Today when working with the I got really tired of uploading everything with Transmit. Since our host doesn’t have support for rsync or something like that, I made this really easy bash-script that will upload everything that have been changed since last time the script was runned.

cd ~/Projects/Pluxemburg/ #local path to site root
find . -newer ./lastupload -exec open -a Transmit "{}" \;
touch ./lastupload

In Transmit, remember that both local and remote paths have been set, and “Use DockSend” enabled. I saved the script as an application using Automator (Automator –> Run Shell Script), and made an icon in 20 seconds. Now I just run the app from QuickSilver or Finder and it uploads everything really fast and easy.

Update: This is for OS X and only tested in 10.4 Tiger

CSS is in progress