I’ve written an applescript in ~/Library/Scripts/Mail Scripts. It works fine when “Run” from inside Script Editor, but when I invoke it from Mail.app’s script menu, I get
“System Events got an error:
NSReceiverEvaluationScriptError: 4”
Why could that be?
(Additional oddity: If the script was saved as an application, then if I click Yes on “Do you want to edit the script?”, it finishes executing! If it was saved as a script, this doesn’t happen. In either case, if I do click Yes to edit, no words are highlighted and the insert cursor is at the end.)
Mail.app is 1.3 (v606). OS is 10.3.1.
The purpose of the script is to switch to my INBOX folder, then restore the drawer’s scroll bar to its previous position. (I have a rather long list of folders.) Here it is.
tell application "Mail"
activate
end tell
tell application "System Events"
tell process "Mail"
set savedValue to the value of the scroll bar of the scroll area of the drawer of the front window as number
end tell
end tell
tell application "Mail"
if (the count of message viewers) is not 0 then
set selected mailboxes of the front message viewer to {mailbox "INBOX" of the first account}
end if
end tell
tell application "System Events"
tell process "Mail"
set the value of the scroll bar of the scroll area of the drawer of the front window to savedValue
end tell
end tell