Martin Ström
my-domain.se

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.

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.


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.


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 harald.net

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


Newer Entries » CSS is in progress