TextExpander: List Browser Tabs
31 Dec 2014Like many of us, the Internet is my go to place for immediate access information. It allows me to quickly research topics via my web browser, but for more involved topics it can be difficult for me to get enough detail in a single sitting, or I may need to pass on some details elsewhere (e.g. a reference list for a document/post/article). But when I have several tabs open (potentially across several windows) it can be a pain to manually list out the links and pages. To that end I created an AppleScript based TextExpander snippet to produce such a list.
Overview
At a high level the snippet works by working through the available browser windows and creating a list of browser tabs. For each tab the snippet then fetches the page’s title and web address (URL). These are then formatted and the formatted list returned for insertion by TextExpander.
Note that because this is AppleScript based it will not work on iOS only OS X devices.
The snippet (specified below) is intended to be customised using a number of settings to meet your specific needs. This means you can set-up the snippet multiple times and just vary the settings to get what you need.
Settings
strBrowser
This string is used to specify which browser to work with. Google Chrome can be specified by setting this string to “Chrome” or to Apple Safari by setting this string to “Safari”. If you favour another browser such as Mozilla Firefox or Opera then it should be possible to extend the functionality of the script to accommodate it (if the browser is scriptable via AppleScript).
strStyle
There are eight in-built formatting styles set by specifying the strStyle variable. These include plain text, hyperlinked HTML, hyperlinked Markdown and various list formatting styles.
Style: Text
Setting the string to “Text” will cause the tab entries to be listed out with the title and URL on consecutive lines and a blank line in between.
Style: HTML-P
Setting the string to “HTML-P” will format the tab entries as HTML. Each tab entry will display the title as the text and will link to the URL. Each tab entry will be enclosed in HTML paragraph tags meaning that when rendered as HTML there will typically be large gaps between entries.
Note: Applying CSS styling may affect any of the HTML or Markdown based output styles when rendering as HTML.
Style: HTML-BR
Setting the string to “HTML-BR” will format the tab entries as HTML. Each tab entry will display the title as the text and will link to the URL. Each tab entry will end with an HTML line break tag meaning that when rendered as HTML consecutive entries will be displayed on consecutive lines.
Style: HTML-UL
Setting the string to “HTML-UL” will format the tab entries as HTML. Each tab entry will display the title as the text and will link to the URL. Each tab entry will be displayed as a bulleted (unordered) list item when rendered as HTML.
Style: HTML-OL
Setting the string to “HTML-OL” will format the tab entries as HTML. Each tab entry will display the title as the text and will link to the URL. Each tab entry will be displayed as a numbered (ordered) list item when rendered as HTML.
Style: MD
Setting the string to “MD” will format the tab entries as Markdown. Each tab entry will be set out as a Markdown hyperlink with the title being used for the link text and the link title and the URL being set as the link URL. Each tab entry will be on a single line and when rendered as HTML would be be displayed on consecutive lines.
Style: MD-UL
Setting the string to “MD-UL” will format the tab entries as Markdown. Each tab entry will be set out as a Markdown hyperlink with the title being used for the link text and the link title and the URL being set as the link URL. Each tab entry will be on a single line and prefixed with an asterisk; which when rendered as HTML would will be displayed as a bulleted (unordered) list item.
Style: MD-OL
Setting the string to “MD-OL” will format the tab entries as Markdown. Each tab entry will be set out as a Markdown hyperlink with the title being used for the link text and the link title and the URL being set as the link URL. Each tab entry will be on a single line and prefixed with a 1 followed by a period (“1.”); which when rendered as HTML would will be displayed as a numbered (ordered) list item.
strLineEnd
The strLineEnd variable is intended to be included at the end of each tab entry. By default (below) it is set as a period (“.”), but you could set it to be an empty string (“”) or any other set of characters you like. For hyperlinked entries (styles other than “Text”), the line end string will be added after the entry and not be included in the hyperlinked text. For the non-hyperlinked entries (style of “Text”), the line end string is included after the title but it is not included after the URL.
Text Substitution
If you examine the AppleScript closely you may notice that there is also a text based substitution routine applied to the tab title. This is set to replace double quotes with single quotes as double quotes are used in setting attributes in HTML and MarkDown links.
Snippet Details
With the above in mind, the snippet details presented below are intended to be amended to suit your needs. Create a snippet and set the settings as you require (below it is defaulted to producing a bulleted Markdown list from Chrome with entries ending with a period), assign a suitable abbreviation then simply replicate and amend for any further variations you might require - I have a half dozen or so combinations I tend to use.
Label | Browser Tab List - Chrome (AS) |
Description | List the open Chrome browser tabs in a hyperlinked Markdown bullet list with entries ending with a period. |
Abbreviation | CTMDUL. |
Content |
|
These snippets can be downloaded as part of the Thought Asylum web snippet group.