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 18, 2014 5:39 PM in response to Leon Buijs

Leon Buijs wrote:


.. and then click single line, yes, I know, but it requires a keystroke and two mouseclicks.


I'd like to find a way to do it with one keyboard shortcut.


Maybe some GUI Scripting :


tell application "Mail" to activate

tell application "System Events"

tell process "Mail"

set flag to (window "Fonts" exists)

if not flag then

keystroke "t" using {command down}

repeat until window "Fonts" exists

end repeat

end if

tell group -1 of splitter group 1 of window "Fonts"

tell menu button 1 of group 1 of group 2

click

click menu item 2 of menu 1

end tell

end tell

if not flag then keystroke "t" using {command down}

end tell

end tell



And just replace “clickmenu item 2 ofmenu 1” withclickmenu item 1 ofmenu 1” to remove strikethrough.

Feb 18, 2014 9:34 PM in response to Pierre L.

Good work Pierre. I had started on this, but got pulled away...


I have modified your code so that it works in Mail and TextEdit (strikethrough style exists). On Mavericks, any GUI scripting must be granted Accessibility privileges via System Preferences > Security & Privacy > Privacy > Accessibility. System Events, Mail, and TextEdit will need to be checked for our scripts to work.


As long as the selected text for the strikethrough has a trailing unselected space, one can click in that unstyled space and resume typing without the strikethrough effect. The strikethrough can be undone with command+Z.


When compiling the AppleScript in Automator, it will pop an error dialog from the Script. This can be ignored and the Script saved as an Automator Service.


User uploaded file

Feb 19, 2014 3:36 AM in response to VikingOSX

Thank you guys both, I really appreciate the effort 🙂 I run into some absolute Automator beginner problems though.

  • I restarted OSX in English, to make debugging this a little easier
  • I started Automator
  • Created a new document
  • Choose 'Service'
  • Choose from the Library: Utilities, from the 2nd column 'Run AppleScript' and dragged it to the 3rd column.
  • Typed the code from VikingOSX
  • Saved it as 'strikeThrough attempt 2'


However, I don't get the color coded look / syntax highlighting on the appleScript and it won't compile, giving a 'syntax error' on line 7:

set flag to (window "Fonts" exits)


The code as I typed it from the screendump:

tell application "System Events"

set activeApps to name of application processes whose frontmost is true

set activeApp to item 1 of activeApps


try

tell process activeApp

set flag to (window "Fonts" exits)

if not flag then

keystroke "t" using {command down}

repeat until window "Fonts" exists

end repeat

end if

tell group -1 of splitter group 1 of window "Fonts"

tell menu button 1 of group 1 of group 2

click

click menu item 2 of menu 1

end tell

end tell

if not flag then keystroke "t" using {command down}

end tell

on error theError number errorNumber

tell me

activate

display dialog "An Error has occurred:" & (errorNumber as text) & return & return & theError buttons {"OK"} default button {"OK"} with icon stop

end tell

end try

end tell


In the menu Mail, Services of Mail, it shows up so that is one thing going right. Can you give me a hint how to get the script working on my machine?

Feb 19, 2014 6:11 AM in response to VikingOSX

Interestingly, although this is enabled and on the option you suggested and work actively in Mail for example, these smart quotes don't seem to work in automator.


Worse: If I copy the code script to Mail and change the quotes to 'smart' ones, and try to compile it again, the compiler error message kicks in, highlighting the double quotes in the first line: Syntax Error Expected expression, property or key form, etc. but found unknown token.


User uploaded file

By the way, is syntax highligting on by default?

Feb 19, 2014 6:47 AM in response to Pierre L.

Pierre, thanks for thinking with me, I'm not sure what special benefits FastScripts brings. I installed FastScripts to give it a try, but it doens't solve the problem, because one still has to create a file in AppleScript Editor and save it, but then it says: Syntax Error Expected “,” but found identifier. — just like in Automator.


(Again, no syntax coloring in AppleScript Editor, I really can't figure out why it's not showing colors, can this be linked to my syntax errors?)

Feb 19, 2014 7:40 AM in response to Leon Buijs

Leon Buijs wrote:


Pierre, thanks for thinking with me, I'm not sure what special benefits FastScripts brings. I installed FastScripts to give it a try, but it doens't solve the problem, because one still has to create a file in AppleScript Editor and save it, but then it says: Syntax Error Expected “,” but found identifier. — just like in Automator.


Unfortunately, I can't explain why the script doesn't work on your computer.


Once FastScripts has been allowed to control my computer in the Security & Privacy preferences, my version of the script seems to work perfectly well on my MacBook Pro under Mavericks.


User uploaded file User uploaded file



Of course, the script also works flawlessly when I add a shortcut to the menu item in the FastScripts menu.


Message was edited by: Pierre L.

Feb 19, 2014 7:51 AM in response to VikingOSX

This fixed the script: Now it shows syntax color highlighting. The script now works as a Service in Mail, as long as one chooses it via the menu bar: Mail / Services / Strikethrough4 (is how I named it)


However, the script does not work via the keyboard shortcut I gave it in System Preferences / Keyboard / Shortcuts / Services / Striketrough4.


You'd think I did something wrong with the keyboard shortcut, but it does trigger the system alert sound.. and if I hit it a few times, an alert pop up: The action “Run AppleScript (StrikeThrough5)” encountered an error.

User uploaded file


PS

I also tried the variation Pierre suggested (setactiveApptonameofapplication process 1 whosefrontmostistrue)

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

Just to be clear: No more syntax errors are shown now.


Indeed, the System preferences / Privacy / Accessibility settings are checked for

  • AppleScript Editor
  • Automator
  • FastScripts
  • Mail
  • System Events
  • SystemUIServer
  • TextEdit


The script runs OK from the Mail / Services menu.


I tried moving it from my ~/Library/Services folder to other places. Where do you keep it?

Feb 19, 2014 8:30 AM in response to Leon Buijs

Inexplicably, various keyboard shortcuts would not work with this Service.


I would leave your Services in the default local Library/Services folder. If you need to edit them in the future, you can either double-click the Service from the Finder, or open Automator and ask it to use a Recent item. If you want to start a Library of AppleScript code, you can copy/paste the AppleScript from the Automator window into a Text Editor and then save as foo.applescript into an arbitrary (e.g. AS folder) in your login directory.


You can also make the local Library folder permanently visible via an open Finder window and pressing command+J to invoke view options.

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.