Home Link

Hello, my name is Brett Terpstra, and it’s nice to meet you. Elegant solutions to complex problems. Curious?

About me

I’m a free­lancer. I’ve worked in inter­ac­tive media/web design, print design, pro­gram­ming, adver­tis­ing and mar­ket­ing. Like any good designer/programmer, I solve prob­lems. I’m espe­cially good at find­ing the right tool for the job, even if that means mak­ing my own. My web­sites and my apps are designed and devel­oped with the goal of being future-proof, main­tain­able and eas­ily built-upon.

I write about tech, and you can often find me blog­ging over at TUAW. Besides being a Mac nerd, I’m a gad­get nerd, a music nerd and I have a strange obses­sion with find­ing the per­fect com­puter keyboard.

I’m avail­able for jobs large and small, and you can con­tact me by click­ing here. I’m usu­ally able to travel as necessary.

Read on »

Mar 08
2010

I posted a way to save your Safari tabs to Ever­note, which I’ve found is gen­er­ally a great way to save book­marks. It syncs auto­mat­i­cally to your other com­put­ers and your iPhone, and it’s fast and easy. If you really want to high­light a few tabs to make sure you get back to them, you might con­sider this script, though. Once you’ve saved your entire Safari brows­ing ses­sion for later, close every­thing except for those spe­cial urls, run the code below as a script, and your open tabs will be saved as entries in your InstaPa­per account.

There are two “prop­erty” lines at the top of the script; edit them to set your Instapa­per user­name and pass­word (if you have one, oth­er­wise, set it to ""). The next sec­tion han­dles every­thing, iter­at­ing through each tab, grab­bing its title and url and build­ing a shell com­mand to do a sim­ple curl call to the InstaPa­per API.

After that, the rest of the script is a rou­tine for url encod­ing that I nicked here. It’s called when set­ting both the _title and _url vari­ables to make the curl call from the shell work. I haven’t tested this exten­sively yet, but it’s worked for every­thing I’ve tried. A title with odd char­ac­ters in it could poten­tially cause prob­lems. You can always add a shell-escaping routine…


property _user : "yourusername"
property _pass : "yourpassword"

tell application "Safari"
    repeat with _tab in tabs of front window
        set _title to my urlencode(name of _tab)
        set _url to my urlencode(URL of _tab)
        set _script to (¬
            "curl 'https://www.instapaper.com/api/add?username="¬
            & _user & "&password=" & _pass & "&url=" & _url & "&title=" & _title & "'")
        set output to do shell script _script
    end repeat
end tell

on urlencode(theText)
    set theTextEnc to ""
    repeat with eachChar in characters of theText
        set useChar to eachChar
        set eachCharNum to ASCII number of eachChar
        if eachCharNum = 32 then
            set useChar to "+"
        else if (eachCharNum ≠ 42) and (eachCharNum ≠ 95) and¬
            (eachCharNum < 45 or eachCharNum > 46) and (eachCharNum < 48 or eachCharNum > 57)¬
            and (eachCharNum < 65 or eachCharNum > 90) and (eachCharNum < 97 or eachCharNum > 122) then
            set firstDig to round (eachCharNum / 16) rounding down
            set secondDig to eachCharNum mod 16
            if firstDig > 9 then
                set aNum to firstDig + 55
                set firstDig to ASCII character aNum
            end if
            if secondDig > 9 then
                set aNum to secondDig + 55
                set secondDig to ASCII character aNum
            end if
            set numHex to ("%" & (firstDig as string) & (secondDig as string)) as string
            set useChar to numHex
        end if
        set theTextEnc to theTextEnc & useChar as string
    end repeat
    return theTextEnc
end urlencode

Open this script in your Script Editor.

Mar 06
2010

Another post, quickly and with less explanation…

The fact that Ever­note processes HTML so much bet­ter than it does plain or rich text got me think­ing and tin­ker­ing. I use Mark­down (actu­ally, Mul­ti­Mark­down) con­stantly, and it does a great job of turn­ing plain text into valid markup. With (Multi)Markdown, even plain text becomes HTML that–when imported into Evernote–retains most of its for­mat­ting. To answer your ques­tion, no, I’m not obsessed with Ever­note, I’m obsessed with prob­lems I think I could solve. It’s unhealthy.

Please note, this requires that you have Fletcher Penney’s Mul­ti­Mark­down installed in ~/Library/Application Support/MultiMarkdown, and that the Perl files (MultiMarkdown.pl and SmartyPants.pl) are located in a ‘bin’ sub­di­rec­tory (which is the default install). If you don’t have Mul­ti­Mark­down, you should get it any­way (all the cool kids have it), so head over to the down­load page and grab a copy. Now, on with the show.

I set this up orig­i­nally as a Text­Mate com­mand, intend­ing just to be able to clip code snip­pets and free-form text to Ever­note with­out think­ing too much about it. That worked well, so I mod­i­fied it to work as a Sys­tem Ser­vice. Specif­i­cally, a Snow Leop­ard ser­vice, but I’m pro­vid­ing the Ruby script here and it can be mod­i­fied for any Mac setup you want.

While it will work just fine on plain text with no markup, it does have a cou­ple of “spe­cial” fea­tures. If you start a line with a # and a space (e.g.: # This is my header), which is a Mark­down con­ven­tion for a first-level head­ing, it will use that as the title for the note and strip it out of the text in pro­cess­ing. It only uses the first one it finds, but it will strip out any first-level head­ers in the selec­tion. I’ll prob­a­bly mod­ify that later, or just have it leave them in. Also, a line that begins with “tags:” fol­lowed by a space and a comma-separated list of words will be split up and used to tag the new note. This is also stripped before pro­cess­ing. It han­dles spaces in multi-word tags, and odd marks at the begin­ning or end of a tag, but only one punc­tu­a­tion char­ac­ter, and only at the begin­ning or end of a tag. The code follows…

Con­tinue read­ing “A bet­ter Sys­tem Ser­vice for Ever­note clip­ping — with MultiMarkdown…”

Mar 06
2010

Just a quick change to my post on the bash func­tion fk that I’ve been using. A small mod­i­fi­ca­tion has greatly improved its usabil­ity: make the can­cel option always be first in the menu. Just move “Can­cel” before the $(fp $1) bit. It’s a lit­tle odd that I didn’t do that to begin with…


fp () { #find and list processes matching a case-insensitive partial-match string
        ps Ao pid,comm|awk '{match($0,/[^\/]+$/); print substr($0,RSTART,RLENGTH)": "$1}'|grep -i $1|grep -v grep
}

fk () { 
    IFS=$'\n'
    PS3='Kill which process? (1 to cancel): '
    select OPT in "Cancel" $(fp $1); do
        if [ $OPT != "Cancel" ]; then
            kill $(echo $OPT|awk '{print $NF}')
        fi
        break
    done
    unset IFS
}

Saving Safari browsing sessions to Evernote

Mar 06
2010

I pri­mar­ily use Safari for web brows­ing, mostly because it’s smoother and faster than Fire­fox, and the Web Inspec­tor is just as use­ful as Fire­bug. As time passes, I end up with a lot of web pages open, and I like to clear out my browser tabs on a reg­u­lar basis. Safari doesn’t really have a long-term session-saving option, so I save lists of open tabs…

Read…

Clippable updated, goes mobile

Feb 26
2010

I’ve pushed out an update to Clip­pable, for bet­ter or worse. In addi­tion to the pre­vi­ously added line num­ber removal for code blocks, it removes spans used in Text­Mate for­mat­ted code and adds some key­board shortcuts:

Left arrow: switch to light on dark Right arrow: switch to black on white Delete key: return to nor­mal for­mat­ting Escape key: return to original page

These fea­tures are added with­out modifying…

Read…

Downtime apology and upcoming projects

Jan 29
2010

I apol­o­gize for the recent down­time, which also affected the Clip­pable bookmarklet’s abil­ity to work. Dreamhost has been pretty awful with down­time lately, and my attempt to switch to a dif­fer­ent phys­i­cal server resulted in a hor­ri­ble mess for myself and sev­eral clients. I have to say that Dreamhost sup­port was extremely help­ful in repair­ing the sit­u­a­tion… their sup­port is the main reason…

Read…

Big Nerd Ranchero

Jan 29
2010

I’m sit­ting at the air­port in Min­neapo­lis, wait­ing for a flight to Atlanta. I’m headed for Big Nerd Ranch for a week-long crash course in iPhone pro­gram­ming. I’ve done a lit­tle, but I think it will be a great way to start from the basics and fill in all of the holes in my knowl­edge. The thing is, I’m a lit­tle torn about the cir­cum­stances; Big…

Read…

A (fairly) simple equation evaluation service for Snow Leopard

Dec 31
2009

Down­load the Eval­u­ate Expres­sion Snow Leop­ard ser­vice: EvaluateExpressionService.zip

This is a stripped down ver­sion of a com­mand I have in the Text­Mate bun­dle we use at TUAW. It allows you to select any basic numeric equa­tion and eval­u­ate it, replac­ing the selected text with the results. It will ignore your text if it con­tains any­thing but num­bers and basic math­e­mat­i­cal sym­bols. Sure, there are…

Read…

Clippable updated to remove source code line numbers

Dec 31
2009

I made a cou­ple of minor changes to the Clip­pable book­marklet, mostly in the way it han­dles Syn­tax­High­lighter code blocks. The Syn­tax­High­lighter plu­gin is used (too) often to for­mat and color code source snip­pets in web­sites. The result when clip­ping a page is that the code you get still has line num­bers, but no option to view the raw source with­out going…

Read…

Designing Draw

Dec 12
2009

Erica Sadun recently released her lat­est app, Draw (iTunes link), into the wilds of the App Store. I take a spe­cial inter­est in this release because I designed the inter­face for it from the ground up. Erica, of course, made all of the magic hap­pen; she’d take my phở­to­shop sketches and send them back as amaz­ing work­ing inter­faces. In the end, it was…

Read…

Where I’ve been this week

Dec 12
2009

Well, I’ve been out of touch with a lot of peo­ple for the last four days, and I thought I’d save some time and pro­vide a place I could link every­one to for a quick expla­na­tion. On Tues­day evening, in the mid­dle of what the weather ser­vice is call­ing our “worst storm in 20 years,” I started hav­ing stom­ach cramps. I won’t go into detail about what followed,…

Read…

My new favorite Bash prompt

Nov 17
2009

I do a lot in Ter­mi­nal. Some­times, it’s eas­ier. Some­times it’s faster. Some­times I’d just rather type it out. What­ever the rea­son, I’ve never been able to stand look­ing at a bor­ing shell prompt. Bash is my pri­mary shell, mostly because I’ve never taken the time to learn much else. I’ll get there some­day. For now, here’s my cur­rent Bash shell prompt…

I’m using…

Read…

Entries (RSS) and Comments (RSS).

Switch to Mobile version