These are particularly useful when I’m writing in a textarea field on a page in one tab and I need to insert the URL of the page in another.
The next snippet is an example of a series of snippets that get the URLs of particular tabs. If I were a little less lazy, I’d try to figure out a way to use browser that’s closer to the “front” of the stack of windows on my screen. This is an arbitrary choice and somewhat unsatisfying. If both browsers are running, Safari “wins,” and the URL will be taken from it.
Note that the two browsers have different ways of getting the URL and the code can’t be unified Chrome doesn’t know what the front document is, and Safari has no active tab index command. If it’s Chrome, the URL is obtained from Lines 10-13. If it’s Safari, then the URL is obtained by calling Safari in Line 7. The abbreviation is furl 2 and the AppleScript content is 1: 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")ħ: tell application "Safari" to get URL of front documentġ1: set frontIndex to active tab index of front windowġ2: get URL of tab frontIndex of front window I’m not sure I have the best solution, but it’s working so far.įirst up is a snippet that inserts the URL of the current page. 1 This is a little bit trickier than writing snippets that are browser-specific or are set to work with the default browser. There’s very little to do to get 1Password working, but all my Safari-specific snippets had to be rewritten to get them to work with Chrome.Īctually, instead of just rewriting them for Chrome, I wanted to make the snippets work for Safari or Chrome, whichever happened to be the browser in use. The first of these has been solved by 1Password’s Chrome extension, and the second by the recent addition of a decent AppleScript library. I can’t live without these snippets, either. It’s not that I’m a big AppleScripter, but every day I use one or more TextExpander snippets that grab and transform the URLs of the pages I’m browsing for insertion into blog posts, notes to myself, and tweets. Two things kept me from giving Google Chrome a decent tryout as my main browser:
Next post Previous post TextExpander snippets for Google Chrome