Archive for the ‘TextExpander Tips’ Category

Random TextExpander Snippets Made Easy

Saturday, December 3rd, 2011

We regularly get requests for a way to choose a random snippet from among a set of snippets. To date, we’ve pointed folks to this technique:

http://nerdgap.com/how-to-randomly-selected-snippets-in-textexpander/

Now that TextExpander itself is AppleScriptable (as of version 3.3), there’s an easier and more flexible way to do this:

  1. Choose File -> New Group
  2. Name the new group Random
  3. Add snippets that you’d like to be chosen at random into the Random group. You can drag existing snippets from other groups into Random, or you can create snippets expressly for use in Random.
    Tip: if you are creating new snippets for use only as random snippets, you can save time and work by not assigning abbreviations to these snippets.
  4. Make a new snippet in a group other than the Random group
  5. Set the Content: of the new snippet to AppleScript
  6. Enter this for the snippet:
    tell application "TextExpander"
    	set groupCount to count (snippets of group "Random")
    	set randomIndex to random number from 1 to groupCount
    	return plain text expansion of ¬
    		snippet randomIndex of group "Random"
    end tell
  7. Set an abbreviation for this new snippet, for example: rrand

Any time you type rrand, you’ll get a random selection from among the snippets in your Random group.

The advantages of this technique over the one linked above are:

  • You need not know the abbreviations for all of the snippets in advance
  • You can add to and remove from your Random group without changing anything

(Thanks to Sheree Peña of Black Pixel for the inspiration for this post.)

AppleScripting TextExpander

Tuesday, April 19th, 2011

TextExpander version 3.3 [download] introduces AppleScript support, primarily oriented toward automating snippet and group management. TextExpander includes AppleScript support for:

  • creating and deleting groups
  • editing group properties
  • creating and deleting snippets
  • editing snippet properties
  • adding (importing) groups from files or from URLs
  • enabling/disabling expansion

These capabilities should be broad enough to allow for some interesting scripts to be created. As you develop scripts, you may encounter some limitations. Your feedback will help determine future expansion of TextExpander’s AppleScript vocabulary.

Here are a couple of sample scripts to get you started. The first one creates a new group and then creates two snippets within it:

tell application “TextExpander”

–– create a new group

make new group with properties {name:”My New Script Group”}

set newGroup to the result

tell newGroup

–– create a snippet, then set the major properties one by one

make new snippet

set newSnippet to the result

set the abbreviation of newSnippet to “tastytreat”

set the plain text expansion of newSnippet to “Toasted marshmallows are a tasty treat”

set the label of newSnippet to “Snippet from AppleScript”

–– create a snippet, setting properties immediately

make new snippet with properties {label:”Second Scripted Snippet”, abbreviation:”scrptwo”, plain text expansion:”Eat Two Marshmallows”}

set secondSnippet to the result

end tell

end tell

The second script checks for the existence of a URL-based group. If no such group is found, that URL is imported:

–– This script checks to make sure that a group based on a particular URL is present.

–– If not, it imports that group

set success to false

set groupURL to (“http://www.smilesoftware.com/te/example.textexpander” as text)

–– note coercion above: TE group source is type text, not URL

tell application “TextExpander”

set sourceList to the source of every group

if sourceList contains groupURL then

–– the desired group is already present

set success to true

else

set newGroup to import URL group using URL groupURL

–– the returned group is a placeholder for URL contents, which are downloaded asynchronously

repeat with i from 1 to 10

delay 1 –– allow some time for download, then poll the group placeholder

tell newGroup

–– find the number of snippets in the group

–– unless the group is supposed to be empty, zero snippets indicates download failure

count snippets

set snipCount to the result

if snipCount is not equal to 0 then

set success to true

exit repeat

end if

end tell

end repeat

end if

end tell

if not success then

beep –– real error handling goes here

end if

 

Again, we welcome your feedback on TextExpander’s new AppleScript capabilities.

Virtual Keyboards and TextExpander

Tuesday, March 29th, 2011

Virtual keyboards are on-screen representations of a keyboard which allow you to enter characters by clicking the mouse or other pointing device. That is, you move the mouse to the part of the screen where the ‘v’ key is, click the mouse, and a ‘v’ appears in your text document. (Note: there are other types of virtual keyboards in addition to the on-screen, mouse-driven variety, but this post does not cover them.) One reason to use a virtual keyboard is if you have trouble typing on a physical keyboard.

Mac Keyboard Viewer

Mac OS X built-in Keyboard Viewer

TextExpander has some issues with virtual keyboards. When you click the mouse, TextExpander assumes that you are moving the text insertion point within a document, selecting a range of text, changing to a different window or text area, or performing some kind of formatting or other command. Thus, when you click the mouse, TextExpander clears the buffer of typed characters it maintains to track when you type a snippet abbreviation.

For example, with the ‘ddate’ snippet, when you click the ‘d’ key on the virtual keyboard the first time, TextExpander clears the buffer because the mouse was clicked, then notices that a ‘d’ has been typed. When you click the ‘d’ key the second time, TextExpander again clears the buffer, then stores the ‘d’. The snippet never expands because TextExpander keeps clearing its buffer, never tracking more than one character at a time.

TextExpander version 3.1 fixed this problem by adding support for typing with the system’s built-in Keyboard Viewer and for Corallo Software’s VirtualKeyboard application. TextExpander 3.2.4 adds support for AssistiveWare’s KeyStrokes application.

If there is another virtual keyboard program that you are using, there is a “hidden” setting in TextExpander that will allow you to use it before support is “built-in” to TextExpander. Just contact support@smilesoftware.com for details.

Using Shell Scripts to Extend TextExpander

Wednesday, October 13th, 2010

In addition to plain text and formatted text, pictures snippets, TextExpander also supports AppleScript and shell scripts as content types. Your abbreviation will expand to whatever the script returns. This allows you to extend TextExpander in whatever ways you need. Here’s a recent example which started with a support question:

> I've created the following snippet with abbreviation: ,getdate:
>
> %date:EEEE% %date:d% %date:LLLL% %date:Y% - día %date:D% del año
>
> Which is converted to the following on my system:
>
> jueves 30 septiembre 2010 - día 273 del año
>
> However, I would like the day of the week and month to be in uppercase, as follows:
>
> Jueves 30 Septiembre 2010 - día 273 del año
>
> Do you know how to do this?

It seems that the Unicode date formatting doesn’t offer a way to specify that the month or day names should be returned in uppercase.

I was able to write a Perl script and to nest the ,getdate snippet to convert the first and third words to uppercase. I set my abbreviation to ,date and my Content: to Shell Script:

#!/usr/bin/perl
$_ = "%snippet:,getdate%";
m/(\S+) (\S+) (\S+)(.*)/;
$_ = ucfirst($1) . " $2 " . ucfirst($3) . "$4";
print "$_\n";

Here is what ,date returns right now with my system set to return date information in Spanish:

Miércoles 13 Octubre 2010 – día 286 del año

That which wasn’t possible before is possible now, thanks to the power of shell scripts in TextExpander.

Fixed A Troublesome TextExpander Bug

Tuesday, August 10th, 2010

Further to our post about disappearing snippets, we have identified at least one issue and have fixed it in TextExpander 3.1.1. We’ve seeded this fix to several customers and have received positive feedback that it fixed the problem for them.

Please download and install the TextExpander 3.1.1 update. If you do experience a snippet loss, please let us know. If there are any other issues, we want to find them.

Per our earlier post, please do the following if you experience the problem:

If you experience this problem, you can restore your snippet library by quitting TextExpander and restoring this file from your Time Machine or other backup:

[Home]/Library/Application Support/TextExpander/Settings.textexpander

Before you re-launch TextExpander, please also send a copy of the restored file to us at textexpander@smileonmymac.com. This is especially helpful if you find the problem recurs for you. If we gather enough settings files, hopefully we’ll find one with which we can reproduce the problem. If we can reproduce it we can almost certainly fix it. In the meantime, we’re very sorry for the inconvenience.

We appreciate your help in making TextExpander the best it can be.

More TextExpander Date and Time Formatting Options

Wednesday, August 4th, 2010

TextExpander 3.1 and TextExpander touch 1.1.6 now support Unicode Date Format Patterns.

This means TextExpander now has support for time zone, era, day of year, and calendar quarter.

For example:

This is day number %date:D% of the current year. We’re now in the %date:qqqq% (%date:qqq%). I’m expanding in %date:zzzz%. Today is %date:yyyy.MM.dd G%.

Expands at the time of writing this post to:

This is day number 216 of the current year. We’re now in the 3rd quarter (Q3). I’m expanding in Pacific Daylight Time. Today is 2010.08.04 AD.

There’s tons of detail in the Unicode Date Format Patterns documentation. Feel free to write us if you have questions.

Shorten your URLs with TextExpander and Clicky.me

Friday, November 27th, 2009

TextExpander comes with an Internet Productivity suite that contains URL shortening snippets for a variety of services including bit.ly and is.gd. One of the newer services that I just discovered is called Clicky. Clicky is a Web analytics package that makes tracking how people are finding and using your Web sites a breeze. As part of the package they also offer a URL shortening service called clicky.me.

I’ve started using clicky.me for all my shortened URLs, and of course I need a TextExpander snippet to do that. The snippet takes any URL that is on your Mac’s clipboard and runs it through Clicky’s API to generate a shortened URL that you can paste into Twitter, Facebook or anywhere you so desire.

Note: You do need a Clicky user account, which is free for low volume users.

Read on for instructions on how to use this snippet.

(more…)

Use TextExpander with Dropbox 2.0

Sunday, October 18th, 2009

UpdateTextExpander 3 has built-in Dropbox sync.  (Preferences > Sync > Dropbox)

  • You are currently browsing the archives for the TextExpander Tips category.