Home Link

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

Archive for the ‘Blog’ Category

  • Jan
  • Feb
  • Mar
  • Apr
  • May
  • Jun
  • Jul
  • Aug
  • Sep
  • Oct
  • Nov
  • Dec

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

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 to var­i­ous appli­ca­tions. I used to use Safari­S­tand to do this, but it got too buggy and slow for me. I use VoodooPad for it, but I like the sort­ing and search­ing option in Ever­note, both on my desk­top, and synced online and to my iPhone.

As much as I love Ever­note, its edi­tor is, well, a has­sle. Import­ing text clip­pings can strip line breaks and leave you with quite a mess, and clean­ing it up is less than pleas­ant. I’ve found that using Apple­Script, HTML and Ever­note together allows me to cre­ate pretty well-formatted notes from web and text clip­pings, aside from using Evernote’s PDF fea­tures. In most cases—like web­site clippings—I don’t need or want a full PDF, replete with ads and com­ments (Clip­pable was designed with that in mind). The trick when cre­at­ing a note in Ever­note via Apple­Script is to use a lit­tle HTML to get the basic for­mat­ting. Evernote’s Apple­Script library pro­vides a com­mand tai­lored to this purpose.

To demon­strate, I’ll show you how to save your brows­ing ses­sion in Safari as a nicely for­mat­ted list in Ever­note. For this I set up a new Note­book called “Book­marks,” and am keep­ing the markup very sim­ple. Ever­note strips most styling from imported HTML, but accepts struc­tural items like head­lines, lists, tables, etc., apply­ing its own default for­mat­ting to the elements.

Con­tinue read­ing “Sav­ing Safari brows­ing ses­sions to Evernote…”

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 formatting
  • Escape key: return to orig­i­nal page

These fea­tures are added with­out mod­i­fy­ing the orig­i­nal book­marklet, so if you’ve got it installed, you’ve got the good­ies already. Oth­er­wise, head over to the Clip­pable book­marklet page and try it out.

The big news, though, is the intro­duc­tion of Clip­pable Mobile. It’s a work in progress, but installs on an iPhone and makes use of the spe­cial for­mat­ting options avail­able in Mobile Safari. It shrinks images, cuts off code blocks, etc., mak­ing every attempt to pro­vide a read­able page that doesn’t scroll hor­i­zon­tally. There are occa­sions where it fails on first attempt, but run­ning it again right away fixes every­thing. I’m still work­ing on fig­ur­ing out why that hap­pens… a lit­tle sleep will prob­a­bly help. Head over to the Clip­pable Mobile page on your iPhone and fol­low the instruc­tions to install it. Bug reports are welcome!

Feb 18
2010

Uploaded by www.cellspin.net

Feb 18
2010

This is a quick test of Cell­Spin, just to see if it does what I think it will.

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 rea­son I’ve stuck with them through the 4 hours of down­time I’d had up to that point. I’m not sure I’ll be able to swal­low much more, but we’ll see if things run as smoothly as they’ve promised from here on out.

In other news, I have a new ver­sion of the Songza ser­vice–one that doesn’t require any addi­tional libraries–which I’ll post soon. A cou­ple of other lit­tle projects are in the works, includ­ing a ser­vice that inter­prets nat­ural lan­guage dates for var­i­ous pur­poses. I’m in Atlanta for a week, then I’ll be in San Fran­cisco cov­er­ing Mac­world for TUAW, so it may be a bit, but I’ll be back!

Entries (RSS) and Comments (RSS).

Switch to Mobile version