TextExpander blog postings

TextExpander Postings

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

February 3, 2016

Time based Greetings in Slack

SlackTextExpander2.jpg

I spend a lot of time communicating with some remote teams. Most of the conversation is done in Slack. Recently I thought of a cool way to implement TextExpander and Slack.

When I start the conversation, I usually do it first thing in the morning with 'Good Morning Champion.' The problem is that in the remote offices it could be afternoon or evening so the greeting is a bit strange. That's when I thought that TextExpander could make the greeting more friendly.

I created several location base snippets that would enter in the proper time greetings based on their location.

Real World Example

There is a snippet in my library for 'in.hello' and this will automatically display the correct greetings when I am talking to my India team in chat. So if it's night time, it would say 'Good Evening Champion' and if it's before 6 pm their time, 'Good Afternoon Champion.' I have sfo.hello, Japan.hello and Korea.hello.

Now I will always say the correct greetings and not have to think about it.

This is the PHP code that I use to get that done:

India Hello Examples

#!/usr/bin/php 
<?php
date_default_timezone_set('Indian/Mauritius');
function greeting(){
    $timeOfDay = date('H');
    if($timeOfDay > '17'){
        return 'Good evening Champion. ';
    } else if ($timeOfDay > '12'){
        return 'Good afternoon Champion. ';
    } else {
        return 'Good morning Champion. ';
    }
}
echo greeting();

?>

I used the PHP Date functionality and not the built in date tools in TextExpander because of portability. I can travel to any time zone and not have to worry about what my system clock says, the greeting will always be correct.

January 27, 2016

Atlasssian Jira Snippets

Atlasssian Jira has some pretty cool features and sometimes it's hard to remember the proper formatting when writing comments. This is especially true if you deal with multiple environments.

So here are three basic snippets that I use to be more productive in Jira.

Code

Jira has a simple code display formatted to display code and log file data. I was using the formatting so many times, that I figured that there should be an easy way to put in the code brackets. Certainly this values a TextExpander snippet. I came up with this very simple solution:

jiracode2

When I originally set this up, I was having problems having the contents on the clipboard get inserted at the same time. This was a problem with Breevy and not TextExpander. I haven't seen any issues with TextExpander.

Hyperlinks

For the longest time, I couldn't remember the proper format to add text formatted hyperlinks. Does the link text come before or after the URL? This can be confusing when you use both WikiMedia and Jira.

Now it's very easy to have hyperlinks, as I only need to remember the simple abbreviation that I created. Here's what the snippet looks like in TextExpander:

Jira Link2

I simply copy the URL that I want to add a link, then I put the cursor in a Jira comment field, I type in Jira.link and the URL is displayed ready for me to type in the text as a link.

Standard Comment

If you comment on a ticket for testing or code review you should have some common header. When I do my testing, I want to highlight if the issue passed or failed and where the testing was done.

This makes it easy for people to read and easily understand some core fundamentals before the have to read all the details. For example, an issue might pass, but perhaps I didn't test it on the right servers, thus I would have a false positive.

Here is my snippet for when I type in 'rready':

Jira Comments2

Closing

These solutions, while simple, have saved me lots of time in writing Jira comments. While today's tip may seem very simple, they are very practical for my everyday needs. They allow me to focus more on the content of what I am typing rather than distract me from making the text good.

January 20, 2016

Spilt Camel Case Snippet

Have you ever encountered a text, such as 'TheSenateReportDocument' or 'LasVegasHotelsReservations' and wanted an easy way to split and display the text. It's very easy to setup a TextExpander snippet to display the text with the proper spaces. To get this done, we'll need a tiny PHP function with preg_replace.

If your not familiar with this text format here's a bit of information from Wikipedia:

CamelCase (also camel caps or medial capitals) is the practice of writing compound words or phrases such that each word or abbreviation begins with a capital letter. Camel case may start with a capital or, especially in programming languages, with a lowercase letter. Common examples are LibreOffice, PowerPoint, iPhone, or in online usernames such as "JohnSmith".

Here's what my TextExpander code looks like:

CamelCase2.jpg

You can simply copy/paste this code:



#!/usr/bin/php

echo splitByCaps('%clipboard');
function splitByCaps($string)
{
return preg_replace('/([a-z0-9])?([A-Z])/','$1 $2',$string);}
?>

I assigned 's.text' as my Abbreviation. Be creative and assign something that you'll remember and not likely mistype.

Now I simply have to copy the text into the clipboard and type in the abbreviation to display the text correctly. In most situations, simply double clicking on the word will select it. So, for example, the TheSenateReportDocument, now become The Senate Report Document.

I find this snippet comes in handy when I have image filenames with CamelCase and I want to insert the proper ALT tag.

January 13, 2016

Unicode in TextExpander

This week's tip is making it easy to insert obscure characters from Unicode for testing purposes. Because having an easy way to insert data types means that I'll actually test it.

The goal of this tip is to insert obscure characters from Unicode in a text field. For me, the content of the text doesn't matter as the ability to validate that users can insert Unicode values and can click submit and the transaction is successful.

Using the "The quick brown fox jumps over the lazy dog" as the phrase is a quick way to verify that the text is processed correctly.

Why I love this snippet

In the past, when I needed to test Unicode data, I would search Google for Unicode table and then pick and choose what values that I want to enter. Very painful and way too time-consuming.

The beauty of this TextExpander snippet is the ability to enter obscure characters from Unicode instantly.

TextExpander Data

TextExpander_Unicode.jpg

Content: Plain Text
Thé qúíćḱ bŕőẃń főx jüṁṗṡ öṿëṛ ẗḧë ḷäżÿ ḋöġ

You can simply modify the above snippet any way you want to make it work for your needs. So now you can insert Unicode whenever you need it and your most likely to test Unicode data.

January 6, 2016

Converting Date/Time to Hours

Every week I send out Code Freeze reminders to the team. Often when I am sending out emails, it would be handy to know exactly how many hours it is until code freeze. This makes it easy for our remote developers to not have to think about covering the time to their local time.

The email reads: On January 7, 2016, Our Release Engineering team will deploy another release. To ensure another quality release, QA has requested that Engineering code freeze on January 5, 2016 at 11:59 pm EST (15 Hours from now)

Since the Code Freeze fluctuates, I setup a TextExpander snippet to calculate the hours until Code Freeze. All I need to do is to select the date, copy it, and then put the cursor where I want the data to appear, and type my abbreviation and BAM the hours appears.

This is what the code looks like in TextExpander:

!/usr/bin/php
date_default_timezone_set('America/New_York');
// Target Format: January 7, 2016 at 12:15 PM $clipboard = "%clipboard";
$releaseday = DateTime::createFromFormat('F j, Y at H:i A', $clipboard);
$today = new DateTime(now);

$diff = $today->diff($releaseday);
$hours = $diff->h;
$hours = $hours + ($diff->days*24);

echo $hours . " hours";
?>

ConvertHours.jpg

My abbreviation for this snippet is: release.hours

Since I am the only one that will be using this feature, I didn't put in any data validation in the PHP script. However, it's certainly best practice to have some additional validation in case someone selects an invalid entry.

The really cool thing is the I can create multiple snippets and have the hours display different hours based on a target location.

December 30, 2015

Getting the Browser Version

Here's another awesome use of AppleScript within TextExpander.

In the past, whenever I create a detail bug report in Jira I would mention the browser that I tested with. So, what I used to do is open up the browser go to the About window and check the version. Then enter in the data in Jira.

The problem is that this is way too time consuming and not something worth doing with every bug report or ticket validation.

Things total changed with TextExpander. Now when I need to include the version of browser I am using, I simple type in chrome.version, safari.version or firefox.version. Having this set up, gives me the ability to add the browser version to every report.

Here's what my chrome.version snippet looks like in TextExpander:

tell application "Google Chrome"
set theVersion to "Chrome:" & version
end tell

Here's a screenshot of all three browser version snippets:

Browser Snippet

You can always modify the text to say "Google Chrome" or just "Chrome." Originally when I set this up I manually typed in the browser name, but I found I was typing the same thing over and over. That's why the name is part of the snippet.

The good thing about this is that I never have to worry about what version I am using, simply by typing in my abbreviation I am guaranteed to always get the latest installed version number. (I don't have to worry about if Chrome did a silent update when I last tracked the browser version.)

This is helpful when doing Google searches too. For example, if I want to know if there's any bugs in my version; I can type in firefox.version and "known bugs" to show me any reported bugs with the version I am using.

Bonus Snippet

What's really cool is that I can combine several of these snippets and get a good browser summary. This is useful for anyone asking what browser version I currently have on my computer. In addition, I can mention in my bug report what browsers I am testing with.

Multiple Browsers

If you use Jira, you can create another snippet so that the text outputs in a Jira table format.

By using today's TextExpander tip it's very easy to display your browser information any place you need it. The good thing too is that you don't need to open up the browser to see the version!

December 23, 2015

Displaying the Browser URL

The ability to run AppleScript from TextExpander is win win situation. Here's another cool snippet using AppleScript that I think you'll enjoy:

Let's say that I find a great article on Boston.com that mentions the company that I use to work at. I decide to share some of the content to a former co-worker. So, I cut and paste the relevant text from the browser and compose a new email message with that text. Now if I want to include the URL, I would have to go back to the browser and copy the URL and then paste it in the email.

With TextExpander and some very basic AppleScript I don't have to go back anymore! I created a snippet to get the URL of the browser. Since I have multiple browsers on my computer I have a couple of snippet setup.

TextExpander URL

Here's a sample code for Chrome, don't forget to set the Content to AppleScript:

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

The abbreviation that I assigned the task is very easy to remember: chrome.url and safari.url

Now where ever I want to share the URL of the page I am looking at, I just need to remember what browser I used.

What about Firefox?

Apparently Firefox removed the ability to use AppleScript in the latest version due to some technical reasons.

You can read all about the latest Apple/Firefox drama in Bug 516502 "Re-add AppleScript support for getting the current URL" bug report.

December 16, 2015

Quick Phone Number formating

JavaScriptPhone.jpg

Today's TextExpander tip is a simple tool to convert a phone number into a more readable type of format.

Every once in a while I'll need to convert a nine digit number such as 8004249090 to an easier readable format such as (800) 424-9090.

This is the Javascript snippet that I use in my TextExpander library:

var pnum ="%clipboard";
    var numbers = pnum.replace(/D/g, ''),
        char = {0:'(',3:') ',6:' - '};
    pnum = '';
    for (var i = 0; i < numbers.length; i++) {
        pnum += (char[i]||'') + numbers[i];
    }

I call my abbreviation .pformat.

So, now when I encounter the nine digit number, I can simply copy the number and then type in .pformat and POOF! the format appears.

If you know some basic JavaScript, you can easily change up the function above to make the number display any way you want.

December 9, 2015

JavaScript for OS X Automation in TextExpander

JavaScript for OS X Automation

This week's tip is a brief example of how to use JavaScript for OS X Automation in TextExpander. TextExpander started supporting JavaScript for OS X Automation or (JAX) in version 5.0.

JavaScript for OS X Automation is Apple ways of opening up key Applications to create tiny time-saving Applications. You don't need to be a programmer to appreciate the power of this new functionality in OS X Yosemite.

I'll show you how to set up a simple TextExpander Snippet to view a Jira ticket with whatever text is in the clipboard. This is a quick way to view a ticket if you don't have a link to click on.

Create the following JavaScript Snippet in TextExpander:

Browser = Application("Google Chrome");
window = Browser.windows[0];
window.name();
myclipboard = "https://company.atlassian.net/browse/" + "%clipboard";
tab = Browser.Tab({url:myclipboard});
window.tabs.push(tab);

Note: This particular snippet is using Google Chrome, you can change the browser type to 'Safari' or 'FireFox' if you would rather use those browser types.

Change the Atlassian URL to whatever the URL that your company is currently using for their Jira installation.

I assigned '.doit' as the abbreviation, so its unique and simple to remember.

Now when I get an inquiry about an issue via Slack, I just copy the issue number and type in the abbreviation. Google Chrome opens up a new tab and the Jira page is displayed.

This is a very simple implementation, but what's cool is that I can easily modify this to open up multiple tabs to do something else. For example, I can easily open up two tabs to handle the same query. So I could search for something in Jira in one tab and at the same time have another tab search Papertrail for the same clipboard data.

I am excited to see JAX implementation in TextExpander. I believe that there's a lot of opportunities to make me more productive.

December 2, 2015

TextExpander URL Subdomain Slicer

Today's snippet example is highlighting the power of built in JavaScript utilities with TextExpander. Both are pretty powerful tools and lots of flexibility. Together they make you super productive.

subdomain_js.jpg

JavaScript has a lot of very cool built in text utilities. You can easily implement some of these in TextExpander. This week we are going to look at a cool use of the JavaScript slice tool.

In my testing enviroment we have different subdomains and sometimes I just need to reference the one I am working on. So I created this simple TextExpander JavaScript snippet:

JavaScript Snippet

var mylocation = '%clipboard';
var start = mylocation.indexOf("://")+3;
var end = mylocation.indexOf(".")
var domain = mylocation.slice(start,end);
domain;

Snippet Abbreviation

ddomain

Real World Use

When I comment in a ticket, I can now easily reference the server that I am working on as part of the description text:

I am encountering a problem on the dev20 server when trying to login:
https://dev20.serverbot.com/login