Mar 08
2010
I posted a way to save your Safari tabs to Evernote, which I’ve found is generally a great way to save bookmarks. It syncs automatically to your other computers and your iPhone, and it’s fast and easy. If you really want to highlight a few tabs to make sure you get back to them, you might consider this script, though. Once you’ve saved your entire Safari browsing session for later, close everything except for those special urls, run the code below as a script, and your open tabs will be saved as entries in your InstaPaper account.
There are two “property” lines at the top of the script; edit them to set your Instapaper username and password (if you have one, otherwise, set it to ""). The next section handles everything, iterating through each tab, grabbing its title and url and building a shell command to do a simple curl call to the InstaPaper API.
After that, the rest of the script is a routine for url encoding that I nicked here. It’s called when setting both the _title and _url variables to make the curl call from the shell work. I haven’t tested this extensively yet, but it’s worked for everything I’ve tried. A title with odd characters in it could potentially cause problems. 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 Evernote processes HTML so much better than it does plain or rich text got me thinking and tinkering. I use Markdown (actually, MultiMarkdown) constantly, and it does a great job of turning plain text into valid markup. With (Multi)Markdown, even plain text becomes HTML that–when imported into Evernote–retains most of its formatting. To answer your question, no, I’m not obsessed with Evernote, I’m obsessed with problems I think I could solve. It’s unhealthy.
Please note, this requires that you have Fletcher Penney’s MultiMarkdown installed in ~/Library/Application Support/MultiMarkdown, and that the Perl files (MultiMarkdown.pl and SmartyPants.pl) are located in a ‘bin’ subdirectory (which is the default install). If you don’t have MultiMarkdown, you should get it anyway (all the cool kids have it), so head over to the download page and grab a copy. Now, on with the show.
I set this up originally as a TextMate command, intending just to be able to clip code snippets and free-form text to Evernote without thinking too much about it. That worked well, so I modified it to work as a System Service. Specifically, a Snow Leopard service, but I’m providing the Ruby script here and it can be modified for any Mac setup you want.
While it will work just fine on plain text with no markup, it does have a couple of “special” features. If you start a line with a # and a space (e.g.: # This is my header), which is a Markdown convention for a first-level heading, it will use that as the title for the note and strip it out of the text in processing. It only uses the first one it finds, but it will strip out any first-level headers in the selection. I’ll probably modify that later, or just have it leave them in. Also, a line that begins with “tags:” followed 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 processing. It handles spaces in multi-word tags, and odd marks at the beginning or end of a tag, but only one punctuation character, and only at the beginning or end of a tag. The code follows…
Continue reading “A better System Service for Evernote clipping — with MultiMarkdown…”
Mar 06
2010
Just a quick change to my post on the bash function fk that I’ve been using. A small modification has greatly improved its usability: make the cancel option always be first in the menu. Just move “Cancel” before the $(fp $1) bit. It’s a little 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
}
Mar 06
2010
I primarily use Safari for web browsing, mostly because it’s smoother and faster than Firefox, and the Web Inspector is just as useful as Firebug. As time passes, I end up with a lot of web pages open, and I like to clear out my browser tabs on a regular basis. Safari doesn’t really have a long-term session-saving option, so I save lists of open tabs to various applications. I used to use SafariStand to do this, but it got too buggy and slow for me. I use VoodooPad for it, but I like the sorting and searching option in Evernote, both on my desktop, and synced online and to my iPhone.
As much as I love Evernote, its editor is, well, a hassle. Importing text clippings can strip line breaks and leave you with quite a mess, and cleaning it up is less than pleasant. I’ve found that using AppleScript, HTML and Evernote together allows me to create pretty well-formatted notes from web and text clippings, aside from using Evernote’s PDF features. In most cases—like website clippings—I don’t need or want a full PDF, replete with ads and comments (Clippable was designed with that in mind). The trick when creating a note in Evernote via AppleScript is to use a little HTML to get the basic formatting. Evernote’s AppleScript library provides a command tailored to this purpose.
To demonstrate, I’ll show you how to save your browsing session in Safari as a nicely formatted list in Evernote. For this I set up a new Notebook called “Bookmarks,” and am keeping the markup very simple. Evernote strips most styling from imported HTML, but accepts structural items like headlines, lists, tables, etc., applying its own default formatting to the elements.
Continue reading “Saving Safari browsing sessions to Evernote…”
Dec 31
2009
Download the Evaluate Expression Snow Leopard service: EvaluateExpressionService.zip
This is a stripped down version of a command I have in the TextMate bundle we use at TUAW. It allows you to select any basic numeric equation and evaluate it, replacing the selected text with the results. It will ignore your text if it contains anything but numbers and basic mathematical symbols. Sure, there are plenty of ways to do calculations in OS X (Spotlight, Launchbar, Quicksilver), but I’ve had more and more incidents lately where I just wanted to do quick calculations inline, so I whipped this up. A little explanation…
Continue reading “A (fairly) simple equation evaluation service for Snow Leopard…”
Dec 31
2009
I made a couple of minor changes to the Clippable bookmarklet, mostly in the way it handles SyntaxHighlighter code blocks. The SyntaxHighlighter plugin is used (too) often to format and color code source snippets in websites. The result when clipping a page is that the code you get still has line numbers, but no option to view the raw source without going back to the web page. Then you end up manually editing out the line numbers if you want to copy and paste the code, which can be a pain in most cases.
Since the point of Clippable was to deal better with things like code blocks (especially for saving snippets to Evernote), it now removes the toolbar and line numbers from SyntaxHighlighter blocks. It also looks for another common technique: converting lines in code to an ordered list inside of a pre block. This is just blotted out with CSS now. Those are the only two highlighting methods it targets at the moment, but I’ll tackle more as I run into them.
If you already have the bookmarklet installed, you’re already benefitting from these changes (the bookmarklet calls the source scripts on my server, so it is, in essence, automatically updated). If not, just cruise over to the Clippable page and grab it!
Nov 17
2009
I do a lot in Terminal. Sometimes, it’s easier. Sometimes it’s faster. Sometimes I’d just rather type it out. Whatever the reason, I’ve never been able to stand looking at a boring shell prompt. Bash is my primary shell, mostly because I’ve never taken the time to learn much else. I’ll get there someday. For now, here’s my current Bash shell prompt…
I’m using the PROMPT_COMMAND variable to run a few quick functions to generate the prompt. It doesn’t do anything processor-intensive, so I haven’t seen any lag caused by this one (unlike some of my previous experiments). PROMPT_COMMAND is set to call a function called, appropriately, prompt_command(). This, in turn, calls a few external functions defined in my .bash_profile. To use it, just stick all of the code below into your .bash_profile, and modify it as you see fit. Be sure to replace any definitions of PROMPT_COMMAND or PS1.
Continue reading “My new favorite Bash prompt…”