Never forget a Mail attachment using TextExpander

Philip Blog, TextExpander

Do you sometimes forget to include an attachment in an email? We had a customer seeking a foolproof solution to guarantee that he wouldn’t type “attached” without also attaching a file. He was seeking a solution using another software package, but it inspired us to create the following slightly simpler solution using just TextExpander and Mail.

Create a Mail-only Snippet Group

Create a new snippet group and name it “Mail only”. To set a group to only expand in Mail, set the “Expand in:” menu to “Only These Applications…”, then select Mail from the list which follows.

Setup an Applet

Launch the AppleScript Editor which is found in your Utilities folder and create the following script:

tell application "System Events"
    delay 0.4 -- wait a bit for snippet 'replacement' to appear
    keystroke "a" using {command down, shift down} -- key equivalent for Attach Files
end tell

 

  1. Choose File -> Save…
  2. Set the filename to: AttachFilesKeystroke
  3. Save to your Applications folder:

Create a Snippet

In TextExpander, create a new snippet in your “Mail only” group, and set its “Content:” type to “AppleScript”.

Insert the following text for the replacement:

do shell script “open -g /Applications/AttachFilesKeystroke.app/”
return “attached”

Finally, set the abbreviation to “attached”, and for bonus points, set the Abbreviation type to “Adapt to Case of Abbreviation” so that the snippet will work for both “Attached” and “attached.”

Now, whenever you type “attached” in Mail, you’ll hear TextExpander’s expansion sound followed by the appearance of the Attachment selection dialog. If you have already attached the file, just press the Escape key to dismiss the dialog and continue typing.

If this is too intrusive for you, you can always change the abbreviation to something like “atttach”, but then you run the risk of forgetting an attachment.

Geek Notes

The open -g shell command opens the specified item without activating the application. This allows the focus to stay in Mail.

The snippet returns the abbreviation, so this snippet doesn’t really “expand”, but the key to getting this working is having the applet start up in the background and begin taking actions after a short delay. This strategy can be adapted to begin other actions based on a snippet expansion, including telling other applications to perform actions.