apple   art   china   net culture   productivity   reading   shots/pics   stories   tech   work

Textexpander snippets to pull frontmost Safari or Chrome webpage title and URL
15 September 2011

Inspired by an (Applescript) Textexpander snippet of Dr.Drang I created two snippets to make linking to a page a little easier for me.

First we need this snippet/script, called !furl, to pull the URL from Safari or Chrome:

tell application "System Events"
set numSafari to count (every process whose name is "Safari")
set numChrome to count (every process whose name is "Google Chrome")
end tell

if numSafari > 0 then
tell application "Safari" to get URL of front document
else
if numChrome > 0 then
tell application "Google Chrome"
set frontIndex to active tab index of front window
get URL of tab frontIndex of front window
end tell
end if
end if

(via furl at master from drdrang/te-url-snippets – GitHub)

And this one, called !fname, to pull the title from the frontmost webpage:

tell application "System Events"
set numSafari to count (every process whose name is "Safari")
set numChrome to count (every process whose name is "Google Chrome")
end tell

if numSafari > 0 then
tell application "Safari" to get name of front document
else
if numChrome > 0 then
tell application "Google Chrome"
set frontIndex to active tab index of front window
get name of tab frontIndex of front window
end tell
end if
end if

Now these snippets can be used, for example, to create links for Twitter with this snippet:

%snippet:!fname% %snippet:!furl%

or to create a proper blockquote (I use Textpattern, therefore this is a Textile) blockquote). Note that you have to select and copy the text that you want to show up in the blockquote first:

bq. %clipboard

(via "%snippet:!fname%":%snippet:!furl%)