July 2, 2017

Chrome TextExpander Snippets

Using TextExpander and AppleScript, I can easily get the current URL of the Chrome browser. This is useful when I want to share the URL in an email, Slack or a blog post.

Simple setup to get the URL in TextExpander

I have two Snippets setup, one to get the URL and one to get the title of the page:

tell application "Google Chrome"
 set theURL to URL of active tab of window 1
end tell

Defined as: snippet:chrome.full.url

tell application "Google Chrome"
 set theTitle to TITLE of active tab of window 1
end tell

Defined as: snippet:chrome.title

Line Work

Along with that setup, I have several other Snippets that references the above snippets. These are useful to have as I may want to display the URL differently depending on what applications that I am using.

Chrome Link with the Title

Very useful when the page title is suitable for a link:

<a href="%snippet:chrome.full.url%">%snippet:chrome.title%</a>

Just the Chrome Link

Create the anchor tag with the Chrome URL and put the cursor where I can enter in the link text

<a href="%snippet:chrome.full.url%">%|</a>

Chrome Url with Clipboard Text

Create a link to the site using the content of the clipboard as the link text

<a href="%snippet:chrome.full.url%">%clipboard</a>

Rich Text Format

I created a rich text snippet for email and Word Document

Rich Text HTML Chrome

Technical Notes

As you can see, it's really handy to have a couple of base snippets that are being used by other snippets.

In addition, if Apple or Chrome should change the Javascript functionality, I'll only have to change it in one place.

Comments

Add your Comments

Feel free to leave a comment about this post.

- Feel Free to add HTML to your comment!