TextExpander logo TextExpander Smile logo
 

Help: AppleScripting TextExpander

You can use AppleScript to change many of TextExpander's preferences, or to add or remove snippets and groups.

Scriptable Preference Settings

The preferences you can access or change via AppleScript include some of the settings available in TextExpander's Preferences window as well as several settings which do not have any corresponding controls.

expansion enabled
A boolean flag controlling whether expansion (and capitalization correction) is enabled.
(See Expansion Preferences)
include HTML
A boolean flag controlling whether HTML data is included on the pasteboard when inserting Formatted snippet content.
(See Expansion Preferences)
restore pasteboard
A boolean flag controlling whether the previous pasteboard contents are restored after Pasting snippet content.
(See Expansion Preferences)
capitalize new sentences
A boolean flag controlling whether capitalization correction automatically capitalizes the first word new sentences.
(See Options Preferences)
suppress double capitals
An enumeration controlling whether capitalization correction corrects two capital letters at the start of a word to just one.
(See Options Preferences)
restore clipboard regardless

A boolean flag controlling whether TextExpander will restore a clipboard that does not match the snippet content that it placed there to expand a snippet. This is useful if an application or utility modifies the contents of the pasteboard.

For example, TextMate 1.5.10 modifies the pasteboard as soon as text is placed on it, resulting in TextExpander not restoring the previous clipboard contents.

tap key up events

A boolean flag controlling whether TextExpander will tap key-up events as well as the key-down events that it normally taps to detect when you type a snippet abbreviation.

This can help make TextExpander work better with other applications or hardware drivers that generate artificial keystrokes, such as Nuance's Dragon products, or the Microsoft IntelliPoint mouse driver.

avoid querying keyboard layout

A boolean flag controlling whether TextExpander will avoid querying the active Input Methods for keyboard layout information.

This can help avoid slow typing with certain Input Methods, such as the Sugou IM. However, it also prevents TextExpander from detecting the correct 'V' key (for sending Command-V to Paste in snippet expansions) when using, for example, the Dvorak keyboard layout.

always pause before Pasting

A boolean flag controlling whether TextExpander will pause briefly before Pasting, regardless of which application is active while expanding a snippet.

TextExpander places the snippet expansion on the clipboard, then immediately sends Command-V to Paste it in. Some applications seem to require a short delay in order for the new clipboard contents to "register" and the expansion to work as desired. A pause before Pasting can help overcome problems with the pasteboard contents appearing instead of a snippet expansion, possibly because some clipboard utility is modifying or otherwise slowing the change of the pasteboard.

By default, TextExpander pauses before Pasting in: Pages, Numbers, Keynote, Mail, Spotlight, Fantastical, Xcode, and most Microsoft applications.

pause before Pasting bundles
A list of text strings with the bundle IDs (ex. com.apple.Safari) of additional applications to pause before Pasting into (the default applications are listed above).
pause before Pasting time
A real number controlling the number of seconds TextExpander will pause before Pasting (when pause applies). The default value is 0.2 seconds.
pause after Pasting bundles

A list of text strings with the bundle IDs (eg. com.apple.Safari) of additional applications to pause after Pasting into.

After TextExpander sends Command-V to Paste in snippet content, it may send additional keystrokes very quickly immediately afterwards. If you are expanding with delimiters, or your snippet contains Tab, Return, etc. keystrokes, or arrow keys are required to place the insertion cursor at some location within the snippet, some applications seem to require a short delay to process the Paste before receiving subsequent keystrokes. If snippet parts are appearing in the wrong order or wrong locations, try adding the application to this list.

By default, TextExpander pauses after Pasting into: Pages, Numbers, Keynote, Microsoft Word, Microsoft Powerpoint, Safari, Google Chrome, Firefox, Camino, and SeaMonkey.

pause after Pasting time
A real number controlling the number of seconds TextExpander will pause after Pasting (when pause applies). The default value is 0.2 seconds.
avoid expansion bundle prefixes

A list of text strings with the bundle IDs (or partial prefixes, eg. com.mozilla will cover com.mozilla.firefox and com.mozilla.camino, etc.) of applications to avoid expanding or correcting capitalization in.

By default, TextExpander avoids expanding into applications where the bundle ID begins with com.parallels or com.vmware.

This can be useful to prevent TextExpander from interacting with certain applications or Java applets which do not appear in the "all applications, except..." listing in Expansion Preferences. (To prevent expansion in Java applets, add com.apple.javajdk16.cmd to this list (change appropriately for different versions of the JDK).)

allowed computation time
Seconds before snippet content computation times out. By default, TextExpander allows script snippets 5 seconds to compute. This value can be adjusted up to 28 seconds if some of your script snippets take a long time to execute.
unibar bundle_role_identifier triplets

A list of strings in triplets:

  • Bundle ID - application bundle identifier such as com.google.Chrome (used in a case-insensitive comparison)
  • AXRole - the Accessibility Role of a focused text item, such as AXTextField
  • AXIdentifier - the Accessibility Identifier of a focused text item, such as WEB_BROWSER_ADDRESS_AND_SEARCH_FIELD

These triplets define text areas within applications where Shift-Left-Arrow keystrokes will be used to remove/replace the snippet abbreviation instead of the usual Backspace. (Browser "unibars" respond better to Shift-Left-Arrow keystrokes.)

ignore clicks in bundles

A list of text strings with the bundle IDs of applications to allow mouse clicks in without resetting the typing log (eg. virtual keyboards). That is, usually any mouse click will clear the typing log, so if you type part of an abbreviation, click the mouse, then finish the abbreviation, TextExpander will not expand the snippet.

By default, TextExpander ignores clicks in: the system's KeyboardViewer, KeyStrokes (by AssistiveWare), and VirtualKeyboard (by Corallo Software).

expand with repeated keys
A boolean flag controlling whether TextExpander will expand snippets when keys are held down to repeat letters. By default, repeated keys do not trigger expansion or capitalization correction.
non expanding language codes

A list of text strings with the two-letter language codes of Input Methods where expansion is disabled.

By default, TextExpander does not expand when using Input Methods identified with any of the following language codes: "ja", "zh", "sa", "ar", "hi" (Japanese, Chinese, Sanskrit, Arabic, Hindi).

additional contraction characters
A text string containing punctuation characters in addition to apostrophe and right single quotation mark to be treated as letters by capitalization correction. (eg. "i'm" corrects to "I'm")
adjust linebreaks after empty optional parts
A boolean flag controlling whether TextExpander will try to remove what will seem like an extra blank line if an optional section of a fill-in snippet is not included. That is, if an optional section which starts on a new line is not checked, and there is a line break just afterwards, that linebreak will not be expanded in the snippet. TextExpander defaults to performing this adjustment.
adjust linebreaks after linebreak keystrokes
A boolean flag controlling whether TextExpander will avoid expanding what may be an extra blank line if a %key:return% or %enter% is followed by a line break. TextExpander defaults to performing this adjustment.
include paragraphs in HTML

A boolean flag controlling whether TextExpander will include <P> tags and associated styles with HTML data. <P> tags are only included if the snippet contains linebreaks.

TextExpander defaults to including paragraph tags for multi-line snippets.

Scripting Groups and Snippets

You can use AppleScript to access snippet groups by name, or you can enumerate through all the groups. Once you access a group, you can enumerate the snippets it contains. Group and snippet properties can be edited. You can create or delete groups or snippets.

Here is a sample script which changes any Formatted text snippets in the My Snippets group to be Plain Text snippets instead:

tell application "TextExpander"
set theGroup to group "My Snippets"
set theSnippets to snippets of theGroup
repeat with theSnip in theSnippets
if ((content type of theSnip) = rich_text) then
set the content type of theSnip to plain_text
end if
end repeat
end tell

Expanding Snippets

You can use TextExpander's expand command to expand a snippet into the currently active application. You can either specify a snippet reference (expand snippet aSnippet), or you can provide a snippet abbreviation (expand abbreviation "abbreviation").

Here is a sample script that creates a reply to the currently selected message in Mail and inserts a snippet as the reply text:

-- create a reply to the currently selected Mail message with a snippet
tell application "Mail"
activate
set current_messages to selected messages of message viewer 1
set theMessage to last item of current_messages
set new_message to reply theMessage with opening window and reply to all

tell application "TextExpander"
expand abbreviation ";fbreply"
end tell
end tell

 
 
© 2006-2014 SmileOnMyMac, LLC, dba Smile. All rights reserved.
TextExpander is a registered trademark, Smile and the Smile logo are trademarks of SmileOnMyMac, LLC, dba Smile.