I use “select line” all the time in my programming editors and was recently missing it enough in Apple Mail to do something about it.
Unfortunately using simple key aliases in a macro caused some side-effects due to all of my customizations, so I wrote an AppleScript that requires the front window to be an outgoing email.
For speed I put all the actions in the AppleScript as raw XML and run them directly with the Keyboard Maestro Engine.
This will run a trifle faster if you convert the text AppleScript to a compiled script.
I'm running it from FastScripts myself, and that's a little faster yet on my machine.
Basically all I'm doing is running the emacs emulation available in Cocoa apps.
⌃A ⌃⇧E
And this will select a paragraph if there is one.
To select only the current line use this key combination:
AppleScript complete with XML for Keyboard Maestro Actions.
----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2019/02/25 09:41
# dMod: 2019/02/25 09:41
# Appl: Mail, Keyboard Maestro Engine, System Events
# Task: Select the Current Line in the Current Outgoing Message.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Keyboard_Maestro_Engine, @Mail, @System_Events, @Select, @Current, @Line, @Outgoing, @Message
# Vers: 1.00
----------------------------------------------------------------
--» XML for Keyboard Maestro Actions to run Directly from AppleScript.
set macroXML to "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<!DOCTYPE plist PUBLIC \"-//Apple//DTD PLIST 1.0//EN\" \"http://www.apple.com/DTDs/PropertyList-1.0.dtd\">
<plist version=\"1.0\">
<array>
<dict>
<key>KeyCode</key>
<integer>0</integer>
<key>MacroActionType</key>
<string>SimulateKeystroke</string>
<key>Modifiers</key>
<integer>4096</integer>
<key>ReleaseAll</key>
<false/>
<key>TargetApplication</key>
<dict/>
<key>TargetingType</key>
<string>Front</string>
</dict>
<dict>
<key>KeyCode</key>
<integer>14</integer>
<key>MacroActionType</key>
<string>SimulateKeystroke</string>
<key>Modifiers</key>
<integer>4608</integer>
<key>ReleaseAll</key>
<false/>
<key>TargetApplication</key>
<dict/>
<key>TargetingType</key>
<string>Front</string>
</dict>
</array>
</plist>
"
set continueMacro to false
tell application "System Events"
tell application process "Mail"
tell (first window whose subrole is "AXStandardWindow")
if static text "To:" exists then
set continueMacro to true
else
display notification "Front Window is NOT an Outgoing Message!" with title "Cmd-L" subtitle "" sound name "Tink"
end if
end tell
end tell
end tell
if continueMacro then
tell application "Keyboard Maestro Engine"
do script macroXML
end tell
end if
----------------------------------------------------------------
AppleScript to Detect whether Mail’s frontmost window is an Outgoing Message (extracted from the script above).
----------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2019/02/25 09:41
# dMod: 2019/02/26 05:42
# Appl: Mail, System Events
# Task: Determine Whether the Frontmost Window is an Outgoing Message.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Determine, @Detect, @Frontmost, @Window, @Outgoing, @Message
# Vers: 1.00
----------------------------------------------------------------
tell application "System Events"
tell application process "Mail"
tell (first window whose subrole is "AXStandardWindow")
if static text "To:" exists then
set continueMacro to true
else
display notification "Front Window is NOT an Outgoing Message!" with title "Cmd-L" subtitle "" sound name "Tink"
end if
end tell
end tell
end tell
----------------------------------------------------------------
The keystrokes themselves work fine.
But if I activate them without making sure I'm editing text, they do unexpected things.
Hence the macro to MAKE SURE I'm working with an outgoing message.