You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Mail Strikethrough shortcut

Hi,


For a number of years, I've been waiting for Mail and TextEditor to support the strikethrough text style. You can't make shortcut via OS X System preferences because there is no (text, pulldown )menu for strikethrough.


When I was disappointed again, when I recently switched to OS X Mavericks and found out that Mail 7.1 still doesn't support a keyboard shortcut for strikethrough, I tried to make a shortcut via Automator.. then AppleScript. I found out AS doesn't support rich text.


Is it possible to create a shortcut / trigger a script that copies the selected text in Mail, somehow makes strikethrough text of it, by exporting it to another app that supports strikethrough, then importing it back maybe?



Thanks,

Leon

Posted on Feb 17, 2014 12:58 PM

Reply
Question marked as Top-ranking reply

Posted on Feb 17, 2014 1:12 PM

You can always select text, ⌘T and click User uploaded file

20 replies

Feb 19, 2014 8:44 AM in response to Pierre L.

I put a copy of the script to Macintosh HD/Library/Scripts, so it becomes available via both the mini black and white icons of AppleScript and FastScript.


When I use the script via either of these pulldown menu's, it works fine.


When I use the shortcut CMD-SHIFT-X that I assigned to it in FastScripts, I can tell FastScripts activates because the icon in the menu bar becomes blue, however, it gets stuck and nothing else visually happens.


User uploaded file


It keeps stuck in this (the mouse cursor shows a spinning beachball of death when one hovers over the FastScript icon) untill one triggers the same script via the appleScript menu. Then it says:


Error Number:The action “Run AppleScript (StrikeThrough5)” encountered an error.

«script» doesn’t understand the “stop” message.

Check the actionʼs properties and try running the workflow again.

-212



(I also use Mavericks on a MacBook Pro. I do all testing in Mail of course) Any idea's?

Feb 19, 2014 9:07 AM in response to Leon Buijs

I've moved both of my scripts first to the Macintosh HD/Library/Scripts folder, and then to the Macintosh HD/Library/Scripts/Mail Scripts folder. In each case, I used CMD-SHIFT-X and CMD-SHIFT-Z as the shortcuts, and in each case everything worked well, provided that you remove you fingers from the CMD-SHIFT keys as soon as the X or Z key has been pressed.


Message was edited by: Pierre L.

Dec 4, 2014 6:10 AM in response to Leon Buijs

I have achieved an improvement to GUI scripting as a solution for strike through text in Apple Mail. The following Automator service solution has been tested successfully on the following releases of OS X, and their Apple Mail clients without any code changes:

  • 10.7.5 Lion
  • 10.8.5 Mountain Lion
  • 10.9.5 Mavericks
  • 10.10.1 Yosemite


Example output:

User uploaded file User uploaded file

The solution invokes a Bash shell script from AppleScript. This script massages the raw RTF code derived from what is on the clipboard, and injects the RTF syntax for strike through surrounding your selected text from Apple Mail. It then puts this back on the clipboard, where it is subsequently pasted back into Mail — replacing the original selection. This script is application agnostic, but the results will only work where rich text is supported. If you want to undo the strike through effect, press command+Z to undo it.


The Bash script only needs to be made executable, and preferably locked via Get Info, so you do not accidentally delete it. It can live anywhere you want, providing you synchronize this with the do shell script that launches it, and it is in your search path. Think of the shell script part of this solution as a black box — something you don't need to change, or necessarily understand.


I tried several ways to incorporate the Bash script code in Apple Script for a single file solution, and though it compiled cleanly, it never produced the desired strike through result, until I placed that code in the separate Bash script.


Here is the Bash Script code. Copy/paste into a programmer's editor, not a Word processor, as this must remain pure text with no embedded junk.

#!/bin/bash
#
# rtf_strike.sh
#
# get the raw RTF code from the clipboard, retaining all of the original
# copied selection characteristics (e.g. font, color, size, etc.). Use Perl to
# massage the RTF code, and sed to insert the RTF strikethrough operator
# to produce the strike-through effect on the original selection. Toss it
# back on the clipboard when done.


# Reference
# http://stackoverflow.com/questions/2545289/getting-rtf-data-out-of-mac-os-x-pasteboard-clipboard


/usr/bin/osascript -e 'the clipboard as «class RTF »' | \
/usr/bin/perl -ne 'print chr foreach unpack("C*",pack("H*",substr($_,11,-3)))' | \
/usr/bin/sed -e 's/\\cf/\\strike\\cf/;$s/}$/\\strike0}/g' | /usr/bin/pbcopy


exit 0


In Terminal:

chmod +x ~/rtf_strike.sh


Quit Apple Mail.


Launch Automator, and choose new Service. Service Receives selected Rich Text in Mail. Leave Output replaces ... unchecked.

  • Library > Utilities > Copy to Clipboard — drag/drop into larger workflow window
  • Library > Utilities > Run AppleScript — drag/drop into larger workflow window
    • Select all contents and remove
    • Add AppleScript per Automator screen capture below, and then compile (hammer) it.
  • Save Automator Service with name MailStrike (so it is obvious in your Services submenu)


User uploaded file


In the Mail compose window, select the text that you want to apply the strike through style, then apply the service via Mail > Services > MailStrike.

Mail Strikethrough shortcut

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.