# TextExpander snippet repository

I’ve just created a GitHub repository for all my URL-getting and URL-transforming TextExpander snippets. Most of these are the snippets I talked about in this post last week. The two others are Flickr-specific snippets that I described here and here, but updated to work with Chrome as well as Safari.

The purpose of these snippets is to allow me to write about web pages without constantly switching from my text editor to the browser and back to cut and paste URLs. Since the pages I want to link to are typically showing in the browser window behind the editor, I figured the most efficient solution was to use AppleScript (or the appscript library for Python) and TextExpander to grab those URLs and print them as type—with no context switching.

Some of the snippets transform the URL—typically by shortening—before printing it.

Here’s the repository’s README, which describes all the snippets.

These are the TextExpander snippets I use to capture the URLs of pages I’m browsing and, in some cases, transform them. They use either AppleScript directly or Python with the appscript library and work with both Safari and Google Chrome.

The multibrowser logic works this way:

1. If Safari is running, regardless of whether Chrome is running, get the URL from Safari.
2. If Chrome is running, and Safari isn’t, get the URL from Chrome.

## furl

This is an AppleScript snippet that prints the URL of the frontmost tab of the frontmost browser window (“furl” = “front URL”). I use the abbreviation ;furl to invoke it.

The original version of this snippet (written for TypeIt4Me) is described here. I carried it along when I switched to TextExpander, then generalized it to handle both Chrome and Safari here.

## 1url – 6url

These are AppleScript snippets that print the URL of the nth tab, counting from the left, of the frontmost browser window. I use the abbreviations ;1url through ;6url to invoke them.

These expansions of ;furl were first described here and generalized to work with Chrome and Safari here.

## surl

This is an AppleScript snippet that prints the shortened URL of the frontmost tab of the frontmost browser window (“surl” = “shortened URL”). It uses the Metamark shortening API, which requires special characters in the input URL to be encoded. The escapeurl script, included in the repository, is called by snippet to do the encoding. I use the abbreviation ;surl to invoke it.

Like ;furl this was first written for TypeIt4Me and described here, then generalized to work with Chrome and Safari here.

## 1surl – 6surl

These are AppleScript snippets that print the shortened URLs of the nth tab, counting from the left, of the frontmost browser window. It uses the Metamark shortening API, which requires special characters in the input URL to be encoded. The escapeurl script, included in the repository, is called by snippet to do the encoding. I use the abbreviations ;1surl through ;6surl to invoke them.

These snippets were first described here.

## psurl

This is an AppleScript snippet that prints the shortened URL of the frontmost tab of the frontmost browser window in parentheses. It uses the Metamark shortening API, which requires special characters in the input URL to be encoded. The escapeurl script, included in the repository, is called by snippet to do the encoding. I use the abbreviation (;surl to invoke it.

This snippet was born out of frustration. I often put shortened URLs in parentheses in tweets, and I found myself—because TextExpander insisted on it—invoking ;surl and then going back to put in the parentheses. This snippet made thing go much faster.

This snippet was first described here.

## flickr

This is a shell script snippet written in Python/appscript. It prints the “flic.kr” shortened URL for the Flickr photo in the frontmost tab of the frontmost browser window. I use the abbreviation ;flickr to invoke it.

This snippet was first described here.

## 500

This is a shell script snippet written in Python/appscript. It prints the URL of the smaller medium-sized version (the one that’s 500 pixels wide if landscape) of the Flickr photo in frontmost tab of the frontmost browser window. I use the abbreviation ;500 to invoke it.

This snippet was first described here, then improved to handle more Flickr pages here.