How Do I Move Cursor to the Body of a Apple Mail (AM) Message?
I'm building a macro where I need to copy the entire body of a Mac Mail message. I need to copy it because I need the rich text used in the body to paste into another app (Evernote). I don't think AS or JS can do this, as I think they can only get the plain text of the body. If I'm wrong, please advise.
With Outlook, the FIND command would take me to the body.
But not so in AM.
I've tested and searched, and can find no KB shortcut to move cursor to body.
I can use multiple TABS, but it is unreliable because the number depends on what header fields (bcc, attachments, etc) have been enabled.
Any ideas?
EDIT: Previously I call this "Mac Mail". The proper name if "Apple Mail", so I have changed all references to it to use the proper name.
Can you please give me a clue as to how to do this?
How to use SE to set focus on the Mail body?
This would be after executing a Forward command, which is no problem.
I just looked at the SE Dictionary again, and I didn’t see anything.
But doesn’t this have to be Mail specific?
There is no Mail menu or shortcut (that i have been able to find) to move to body.
------------------------------------------------------------
# Script moves focus to editing panel of front message.
------------------------------------------------------------
tell application "System Events"
if quit delay ≠ 0 then set quit delay to 0
tell application process "Mail"
set frontmost to true -- Just to be sure
tell (first window whose subrole is "AXStandardWindow")
if text field 1 exists then
if text field 1's name is not "To:" then
error "The front window is probably not an outgoing message."
end if
else
error "The front window is probably not an outgoing message."
end if
tell scroll area 1
set its focused to true
end tell
end tell
end tell
-- Just to demonstrate. I'd probably use KM for this.
-- delay 0.05
-- keystroke "a" using {command down}
end tell
------------------------------------------------------------
I've used the [ To: ] field as a check to be sure the front window is an outgoing message window. (Unfortunately Mail.app itself — unlike the blessed Eudora — provides no means to do this.)
The script will work with a new outgoing message, a reply, or a forward.
It's a good idea to use an error-handler in every script, so if it errors you at least know and have some kind of error message (although AppleScript's error messages can be cryptic). AppleScript will fail silently in Keyboard Maestro unless you set the action to output the result — and you generally don't want that.
You're missing the fact that System Events is the agent for GUI-Scripting.
We're actually talking to the UI-Elements of the process — in this case Mail.app.
Some apps have non-standard UI-Elements that are not amenable to GUI-Scripting with System Events (like Firefox), but the vast majority of them can be seen to one degree or another by SEV.
But you cheated! LOL
UI Browswer does all the work for you, including giving you the AppleScript code.
You should have let me in on that “little” secret.
Thanks Enrique! This is huge!
This makes so many things possible, and much easier.
I use the tools at my disposal, and I’ve mentioned more than once on the forum that I use UI Browser (and provided the link).
It’s very helpful, but it doesn’t do all the work.
You should also install Xcode, so you have the Accessibility Inspector.app. It’s not nearly as nice as UI Browser, but sometimes the information it provides is useful in figuring things out.
I want to be able to forward or email but at the end of the body i want to insert a text string
Using Apple Mail
I found on this forum the following question that looks similar to mine:
But the answer is a Applescript which select the whole body text.
I would like to have an Applescript which send me to the end of the body text so i can insert more text there.
All you have to do is remove 1 line from the script to stop it from selecting-all…
keystroke "a" using {command down}
Modify the script.
Then add a Type a Keystroke action to the macro with ⌘↓ to get you to the end of the message body.
Or you change the AppleScript as JM suggests.
In general I prefer to have Keyboard Maestro type keystrokes, but it depends on the situation. Keyboard Maestro is less prone to side-effects from the user pressing keys on the keyboard.
[OS X 11.6, not sure what part of Mail configuration you are looking for]
I simplified this to the following; why is focused still false?
tell application "System Events"
tell application process "Mail"
set frontmost to true
set focused of scroll area 1 of window 1 to true
get focused of scroll area 1 of window 1
end tell
end tell
The reason I need this is a little different the others above: In a macro that uses ⌘K, paste, Return to paste a link on the selected text. After the Return the message no longer has focus. (Mail bug, presumably.) I really want focus to go to the end of the selection, but for now end of the message would be acceptable.
Oddly, without the help of any AppleScript, if I switch applications then go back to Mail, the message body does regain focus, but it’s at the beginning of the message not where the cursor had been. (Good enough – I can ⌘↓ to get to the end of the message, but really ugly.)
My macro is similar, though a little more ambitious. The idea is to be in an application that uses ⌘K to create links, like Mail or TextEdit, switch to Safari, and type the hot key, at which point the macro switches to the previous application, pastes in the Safari page title, selects characters back to the beginning of the pasted text, add the link, and → to the end of the selection. The problem is that after adding the link, the focus is gone — typing a character just produces a beep. Switching away from the application. Yet, if I switch to another application then back, the focus comes back, but at the beginning of, say, the mail message, not where it should be. So I thought maybe doing something about the message body‘s focus would fix the problem.
I went back to the macro to re-enable some steps I had disabled in the process of debugging before posting it for you to see, but of course now it works. It will be interesting to see if and why the problem returns.