How Do I Move Cursor to the Body of a Apple Mail Message?

Hey Mitchell,

Any special reason you're switching to Safari?

In order for AppleScript to work correctly with Safari's front window the app needs to be visible and not hidden. The “Show” action in the following macro unhides Safari if it is hidden – but does NOT activate it – and saves any need to switch to it.

Using System Events to fill the link dialog makes this pretty fast.

Apple Mail → Insert Safari URL from active tab.kmmacros (6.6 KB)

Much more efficient (if rather more arcane) is to create the RTF link directly on the clipboard:

Paste RTF Link on Clipboard from Safari Active Tab Title and URL.kmmacros (7.6 KB)

-Chris

By “switching to Safari” I meant manually — it isn't part of the macro. My description was misleading. Sometimes I am in Mail (or TextEdit, or whatever) when I want to gather the link, and sometimes I am in Safari when I want to add the link to the message (or TextEdit file). I didn't bother making macros for each application I start in, but if I did, then your suggestion to Show instead of Switch would be an improvement.

Also, sometimes I have to switch to Safari from Mail (TextEdit) anyway, because I root around for the tab whose link I want — it‘s not necessarily the one currently frontmost.

In any case, I didn‘t even know that KM had Show actions, so thanks.

Hey Mitchell,

Ah, I see.

Your simplest option then would be to put the RTF link on the clipboard using a global keyboard shortcut and manually pasting it into the app where you want the link.

-Chris

1 Like

Hi @ccstone you had helped my by providing the following. I now get an error.
I'm sure it's because I updated 'mail butler' and I can't remove it because I use one of it's features. I'm sure it has something to do with that.
It's not mission critical, but it was helping me quite a bit.
I appreciate your time.


tell application "Mail"
	activate
end tell

tell application "System Events"
	tell application process "Mail"
		set frontmost to true
		
		tell (first window whose subrole is "AXStandardWindow")
			
			delay 0.05
			
			# Moves focus to the message body.
			tell scroll area 1 to tell UI element 1 to set focused to true
			
			delay 0.05
		end tell
	end tell
end tell