TextExpander blog postings

TextExpander Postings - Page 3

Earliest: October 14, 2015Latest: July 2, 2017Total: 26
November 25, 2015

Parse text using TextExpander

I have to use BuildBot to build branches for testing. This means that I have to fill out a bunch of fields to successfully build the developer box:


Developers are required to create branches with the Jira Ticket number in it, such as this:


To make life easier I created a TextExpander snippet to quickly fill in all the fields in one quick abbreviation. In order to do this, I created a 'helper' Javascript snippet to parse the clipboard text to the Jira issue number out. I'll use this Jira number in the 'reason' field so other people will know what issue I am testing.

Step 1: Create a 'GrepJira' Javascript snippet:

This Javascript code will search for 'XXX-1111' in the clipboard text, you should change the text to whatever three digits for your Jira ticket:

var re = /(XXX-d{2,5})/i;
var str = "%clipboard";
var m;

if ((m = re.exec(str)) !== null) {
if (m.index === re.lastIndex) {
// View your result using the m-variable.
// eg m[0] etc.


I assigned 'GrepJira' as the abbreviation to this snippet. Perhaps a better strategy would be to use tm_GrepJira as an abbreviation, since it's for use only within TextExpander.

Step 2: Create the main snippet that will be used.

This is pretty much entering in a bunch of text separated with some pre-selected data:
cryan%key:tab%qa %snippet:GrepJira%

This is what it looks like using the above example branch name:


To make it a bit easier, I color coded the fields with the text snippet. Hope this helps you get a general idea on how I use parsing text within TextExpander. Hope it helps you create some cool text snippets!

November 18, 2015

Random Email Address for testing

If you have Google Mail, there is a cool trick where you can create instant disposable email addresses. Say you have an email address like coolqa@gmail.com. If you append a "plus" sign to your email username, gmail will ignore anything written between the + and @ sign.

This is helpful tool to have when testing functionality that behaves differently when a unique email addresses is inserted, or if you want to track things that get sent to that email address. In Text Expander I have the following snippet setup:


The above screenshot includes the TextExpander shortcut for 'Postion Cursor Here:' |%

I assigned the above "Plain Text Content" type to the'eemail' abbreviation.

Now when I encounter an email text field where I may need to do some later validation, I type in my shortcut and the placeholder text is entered. The cursor is then position for me to type some identifier in after the plus sign. I can type in some text to remind me of what I am doing, or I can remove the plus and keep the general email.

I could have easily have set it up so that random word generated after the plus symbol. However, I have learned that it isn't always practical. More often than not, it's better to have a practical keyword in place so that if I do get an email I'll have some clue on why I got it.

November 11, 2015

Using TextExpander to Display Date

The date display format for the United States and Europe are a bit different. TextExpander makes it super easy to display the right format when I need it. I just need to remember the correct abbreviation to use, and outputs the correct format that I need:

I have the following snippet setup:

.edate %Y-%1m-%e 2015-11-11
.udate %1m/%e/%y 11/11/2015
today%B %e, %YNovember 11, 2015


In addition, I may want to reference noon time on Thursdays for the weekly team meetings. I always want to always reference the next available occurrence of the meeting. So on Monday, I want to reference this week's meeting and on Friday I'll want to see the date of the next meeting. I have this PHP Shell script set up:

$everytime = date('F j, Y',strtotime('next Thursday'));
echo $everytime;

There?s a lot of possibilities here. Hopefully this helps with some ideas with TextExpander. (For example, not everyone knows that you can use PHP in the Shell Script panel!)

October 28, 2015

Text from an External URL

There are times when I am working where I need to do data validation in an HTML form field. For example, in the phone field the phone number (314) 159-2653 is not valid because the exchange code must begin with 2-9. There are a lot of rules that the North American Numbering plan must follow.

The Automation team has a ticket in queue to do more extensive form validation. However I would like an easy way for me to do the testing whenever I see the form field. Wouldn't it be great to have a way to insert a invalid phone number that may appear to be valid?

How TextExpander Helps

I can set up TextExpander to query a URL and echo the results in a TextExpander format. This gives me a lot of power at my finger tips. In addition, it allows me to expand my programing capabilities - as I am not all that sharp of a Bash or AppleScript programmer. One reason that I may want to do this is because I may want to maintain the code outside of a TextExpander snippets.

For the phone example, I wrote a PHP script on an internal server that echoes an invalid phone number format. For advance programers: You can modify the script so that it produces a valid number based on the parameter that pass through the URL. You can setup a separate TextExpander snippets to query the same URL with a query string so that it returns valid data.

I have the following setup in TextExpander:


Then whenever I encounter a HTML phone form, I just need to type in the assigned shortcut (.tphone) to test that the validation functionality is working.

(406) 036-9588

There is a slight delay with getting the data to appear after I type in the shortcut. However, its very minimal and the data appears much faster than me looking up the rules for a valid phone numbers.

This is an example of a pretty powerful use of TextExpander - having the ability to retrieve external data with a simple keystroke. I'll highlight some other ways that I can use an external server to get data in future blog postings.

October 21, 2015

Going Random with TextExpander

As a tester, I sometimes have a need for a random word. For example, I may need a unique word for creating a new account in my system. Using the Shell Script feature in TextExpander now makes it easy to add a random word whenever I need to.

Here are the simple steps to create a TextExpander Snippet so that you can instantly insert a random word whenever you need it:

random word
  1. Open up TextExpander and create a new Snippet.
  2. Change the script Content type to 'Shell Script'
  3. Enter in the following code:
    lines=$(cat $WORDFILE | wc -l);
    sed -n "$rnum p" $WORDFILE | perl -pe 'chomp'
  4. Click on the 'eye' to get a preview to make sure that it works.
  5. Enter in 'Random Word' as the Label.
  6. Enter 'rrandom' as the Abbreviation. (Makes it easy to remember!)

The root dictionary, /usr/share/dict/words as my random source library is good choice since their are 235,886 words available.

There are many ways to get a random word, I selected using the above method since it seems to be the quickest way. If you know of a better option, let me know!

October 14, 2015

Create Folder on the Desktop

Every Wednesday, I'll highlight one of my personal TextExpander shortcuts. I use TextExpander a lot to be more productive at work.

If you never heard of TextExpander, here's a brief blurb about TextExpander from Smile on my Mac: Save time and effort with TextExpander! Whether it's a simple email signature or several paragraphs of a standard response, you'll love how easy it is to use TextExpander to avoid typing the same thing over and over.

In my option, spending $44 on TextExpander is easily worth the money in long term productivity savings. This is my numbers so far:



I like a clean desktop and so every day I create a new folder with todays date as a filename where I can store all files that I work on that day. I do this so when I am looking for something, I can open that date folder. I find it better than having an out of control Document folder.


There must be a way for me to quickly create a folder on the desktop with today's date.


To simply my daily task, I created a TextExpander Shell Script shortcut called 'xdate' that will run this simple Bash script:

#! /bin/bash
mkdir -p /Users/cryan/Desktop/$(date '+%m.%d.%Y')

I could have easily written it in AppleScript:

tell application "Finder"
do shell script "mkdir -p /Users/cryan/Desktop/$(date '+%m.%d.%Y')"
end tell

By adding the '-p' flag to the mkdir command, no error will be reported if a directory given as an operand already exists. I wanted the option to make sure that if I accidentally type the shortcut I don't see a 'Duplicate Folder' error message.

I am sure there's some practical way to do this by using Apple's launchd manager. Ideally it would be great to have this automatically done every time I login to my computer in the morning. I know that Apple's launchd manager has the ability to do that, and some time when I have a few minutes I'll learn how to set that up.

Hope this helps you write some awesome TextExpander code.