Martin Ström
my-domain.se

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:

of-2.png


Burnfield Dark WordPress Theme issue

I get a lot of questions on how to make the thumbails show up on theme behind this site. So I’ve updated the page with some instructions to help you all.

I’ve started on the 2.0 version on the theme that will (along other features) make thumbnails easier to manage.

Read more


AppleScript to open iTerm tabs for Rails development

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

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"
    activate
    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

What's new in Prototype svn?

Just after posting this I saw that sam tagged the 1.5.1 release in svn so I guess this means that 1.5.1 is final. Great work!

There has been a lot of action the past days in the Prototype SVN; the release of 1.5.1 RC4, the new DOM and Position branches and a lot of other work. Since I watch most of the tickets and changesets I thought I write something about what’s (might be) in the future for Prototype.

DOM branch

I was happy to see a patch I’ve been working on (#7476) to get included some days ago. It will define a new Element#writeAttribute method which will work together as the already existing #readAttribute to work around many issues browsers having with the native set/getAttribute methods (as always mostly in IE) but also to make chaining work:

$('my_image').writeAttribute('src', 'new-image.png').show();

The method will also accept a hash for the attributes to let you set multiple attributes at once:

$('my_image').writeAttribute({src: 'new-image.png', custom_attr: 'foo'}).show();

The patch will also make the Element object into a constructor for very easy and fast element creation (i.e. document.createElement wrapper):

var header = new Element('h1');

The constructor will also accept an optional attributes hash for the attributes (as seen above in the #writeAttribute method):

var header = new Element('h1', {id: 'myHeader'});

Of course chaining will work so for a simple image switcher with preloading you could do this:

<!-- html -->
<img src="thumbnail.jpg" id="thumbnail" hires="big.jpg">

// javascript
$('thumbnail').observe('click', function(event) {
    var thumb = Event.element(event),
      preloader = new Element('img', {src: thumb.readAttribute('hires')});
    preloader.observe('load', function(event) {
        thumb.writeAttribute('src', preloader.readAttribute('src'));
    });
});

Event Branch

I haven’t followed the event branch very closely but from the code and messages on the ML I’ve seen there should be new functionality for better garbage collection (to prevent memory leaks) and for e.g. easier removal of observers from elements.

Where you before had to manually collect all an element’s event listeners to be able to remove them later:

var listener1 = function(event) {...}.bindAsEventListener();
var listener2 = function(event) {...}.bindAsEventListener();

// start listening
$('myElement').observe('click', listener1);
$('myElement').observe('click', listener2);

// stop listening
$('myElement').stopObserving('click', listener1);
$('myElement').stopObserving('click', listener2);

you will now be able to remove all event listener for a specfic event:

$('myElement').stopObserving('click'); // or Event.stopObserving('myElement', 'click');

Other

Some other new additions worth mentioning are:

But to not make this post too long you’ll have to read about it on your own (check the source and/or the changesets manually).

Please notice that all these are subject to change since it’s under development right now and might never get into any future release of Prototype.


Konst & Teknik site finally launched

After five months we finally launched the new site for Konst & Teknik last night. It is my first Ruby on Rails-project and even though it might look pretty simple it has a lot of advanced things going on both server- and client wise. I plan to write more about the development of the site shortly.


One animated background image for multiple elements in Safari

I’ve found out that Safari can’t handle the same animated gif as background for multiple elements, it will just animate one of them at the same time. On a project I’m currently working on my I use the following trick to make all requests to the background image (in this case indicator_black.gif) unique.

[...]
var text = transport.responseText;
if (Browser.WebKit) {
    text = text.gsub('indicator_black.gif', function(match) {
        return match + '?' + new Date().valueOf() +
          Math.round(Math.random() * 5000);
    });
}
[...]

Note that it uses Prototype JavaScript framework and you should too.

Update:

This is fixed in WebKit nightly (and therefore Safari 3 but I haven’t tested yet).

Rails' time extensions ported to JavaScript

I’ve ported Rails’ Numeric Time extensions to JavaScript since I needed to do some date calculations for a project I’m working on. Now one should be able to calculate dates in JS like this:

(5).seconds() // => 5000
(2).weeks() + (2).hours() + (15).seconds() // => 1216815000
(1).week().fromNow().toDate() // => Fri Sep 22 2006 19:16:32 GMT+0200 (CEST)
var date = new Date(2000, 11, 18, 18, 15, 23);
(2).years().since(date).toDate() // => Thu Dec 19 2002 06:15:23 GMT+0100 (CET)

Thought it could be useful for others as well. You’ll need the latest prototype library, unit tests are included.

Download a zip with both .js file and unit tests or just the .js-file.


TextMate Prototype & Scriptaculous Bundle

This the first version of a TextMate bundle for Prototype and script.aculo.us 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.

Prototypish Style Sheet Switcher

This is a Prototypish rewrite of Paul Sowdens Style Sheet Switcher. The original version has a lot of global functions so I put everything into a class instead and made the code a bit more elegant. It should work as the normal one except for some methods have been renamed.

A cookie library is included as well since the switcher needs to read and create cookies to save the users preferred style sheet.

Update

I fixed a bug for pages without any alternate style sheets and updated the script to version 0.2.

Download


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)

autonamed-dump-folder.png

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 name.sh").

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

# 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
    ITEMS="empty"
elif [[ $NUM_ITEMS == 1 ]]; then
    ITEMS="$NUM_ITEMS item"
else
    ITEMS="$NUM_ITEMS items"
fi
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.


Easy FeedBurner redirect

This is a trick I’m using at this site that I picked up somewhere on the FeedBurner Forums. I wanted to have my RSS-feed from this site to go via FeedBurner to get stats etc, but I don’t want to communicate the http://feeds.feedburner.com/xxxx URL public since it might change in the future. So instead, in my .htaccess, I have these lines that will redirect all visitors except FeedBurner itself (otherwise it wouldn’t have any chance to read and parse my feed) to my FeedBurner URL.

RewriteEngine On
RewriteBase /martin/

# FeedBurner
RewriteCond %{HTTP_USER_AGENT} !FeedBurner
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/haraldmartin [R,L]

WordPress theme released

This theme behind this site is now available for download. Read more…


Terminal.app 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.


Pluxemburg upload script

Today when working with the pluxemburg.com-site 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/pluxemburg.com #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


« Older EntriesNewer Entries » CSS is in progress