Sunday, November 29, 2020

#1 2020-11-18 04:34:31 pm

avfc50
Member
Registered: 2020-11-16
Posts: 3
Website

Mail AppleScript opens viewer just fine but will not jump to Message 1

Attached is my AppleScript that opens the current Message Viewer Window just fine but will not jump back to the  INBOX for one of my accounts. The Error Message displayed appears when I try to run it. Many times, I will be in another account when I close the Viewer window, but alway want to be taken back to the newest message in my "INBOX" of account "alf1gm" when I reopen the Viewer window.  Any suggestions how to fix this?

Applescript:


on run
   -- set _inbox to mailbox "INBOX" of account "alf1gm"
   
   tell application "Mail"
       activate
       try
           id of message viewer 1
       on error
           make new message viewer
       end try
       --    tell application "System Events" to keystroke "w" using command down
       delay 1
       set _inbox to mailbox "INBOX" of account "alf1gm"
       set theMessage to message 1 of mailbox "INBOX" of account id _inbox
   end tell
   -- ______________________________________________________
   -- error "Mail got an error: Can’t make mailbox \"INBOX\" of account id \"74319E19-B1D0-45DD-8888-69D49A8C7032\" into type rich text." number -1700 from mailbox "INBOX" of account id "74319E19-B1D0-45DD-8888-69D49A8C7032" to rich text

end run


avfc50, Using Macs Since 1984, Currently on 2017, i7 MacBook Pro. Applescripting since early 1990's. Running Catalina, Mac OS X 10.15.7

Offline

 

#2 2020-11-18 06:19:13 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 981

Re: Mail AppleScript opens viewer just fine but will not jump to Message 1

Hi, You probably want to enforce a selection; something like this should work:

Applescript:

tell application "Mail" to set message viewer 1's selected messages to account "alf1gm"s mailbox "INBOX"'s message 1

Offline

 

#3 2020-11-19 12:46:32 am

avfc50
Member
Registered: 2020-11-16
Posts: 3
Website

Re: Mail AppleScript opens viewer just fine but will not jump to Message 1

Marc, Thanks for the reply.

The code addition you suggested does not give an error when compiled, or when run, but it also does not jump to the "alf1gm" INBOX message 1 when the AppleScript is executed.

It simple stays at whichever folder it was initially in when I closed the message viewer window.

Any other suggestions? Is some system event need to be triggered to force the jump to actually be displayed? I can get an automator jump to display the Jump if I add a Recorded "Mouse Over" and "Click" move, but that is clugie at best.


avfc50, Using Macs Since 1984, Currently on 2017, i7 MacBook Pro. Applescripting since early 1990's. Running Catalina, Mac OS X 10.15.7

Offline

 

#4 2020-11-19 05:40:45 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1444

Re: Mail AppleScript opens viewer just fine but will not jump to Message 1

This is not the first time I have come across this question on the net. The answer is coffin urine. I'll share my solution:

Applescript:


tell application "Mail"
   activate
   
   -- make message viewer 1 if it doesn't exist
   if not (exists message viewer 1) then make new message viewer
   -- message 1 of mailbox "INBOX" of my iCloud account
   set theMessage to message 1 of mailbox "INBOX" of account 1
   -- select the message
   tell message viewer 1 to set selected messages to theMessage
   -- bring message viewer 1 to front, highlight the selected message
   set visible of window of message viewer 1 to true -- important
   
end tell

Last edited by KniazidisR (2020-11-20 09:18:14 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#5 2020-11-19 10:36:22 am

avfc50
Member
Registered: 2020-11-16
Posts: 3
Website

Re: Mail AppleScript opens viewer just fine but will not jump to Message 1

KniazidisR,
Thank you for the useful reply. I tried to run it as a simple AppleScript, but it did not work either.

However, I embedded the code in an Automator App, Recorded a double point and click after your code to select my Inbox Account, Saved and moved the Automator App to my Applications Folder, authorized the Automator app under "System Preferences.../Security & Privacy/Privacy/Accessibility & Full Disk Access, ran it once so I could click the request for authorization dialog boxes. Then ran it one more time to test that it would work in "FULL AUTONOMOUS" Mode.

Without the above level of diligence, Full Autonomous Automation is no longer possible.

Apple has made full automation of processing steps a royal pain in the butt!!

Support Environments like MacScripter have helped me many times to get the Code Right. But, because folks are busy (I guess), they almost never help the beginner get past the coding part and into full production and use of the code. The paragraph above is my attempt to rectify that, since Apples efforts to secure the Mac OS X environment have made my coding effort a lot more tedious.

Sorry for the Rant, but useful coding should not have become this difficult.


avfc50, Using Macs Since 1984, Currently on 2017, i7 MacBook Pro. Applescripting since early 1990's. Running Catalina, Mac OS X 10.15.7

Offline

 

#6 2020-11-19 09:16:36 pm

Marc Anthony
Member
From:: Dallas, TX
Registered: 2006-04-27
Posts: 981

Re: Mail AppleScript opens viewer just fine but will not jump to Message 1

avfc50 wrote:


...because folks are busy (I guess), they almost never help the beginner get past the coding part and into full production...


I don't believe the forum's intent was ever to supply fully fleshed out solutions for newbies, which might actually prevent you from learning. That said, this is a fairly simple task, and it appears my original advice targeted the wrong inbox. This works:

Applescript:

tell application "Mail"
   activate
   if message viewers = {} then make message viewer
   set message viewer 1's selected mailboxes to inbox
   set message viewer 1's selected messages to account 1's mailbox "INBOX"'s message 1 --*
end tell

*edited for option

Last edited by Marc Anthony (2020-11-19 09:25:45 pm)

Offline

 

#7 2020-11-20 09:12:52 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 1444

Re: Mail AppleScript opens viewer just fine but will not jump to Message 1

avfc50 wrote:
KniazidisR,
Thank you for the useful reply. I tried to run it as a simple AppleScript, but it did not work either.



Haste is only needed when catching fleas. You definitely substituted your own for my mailbox, or did you try to dig into mine? You should put into the code some real message existing in your Mail.app and not try to use my Mail.app....................................................

I double-checked. Everything works.  And remove delay 10 at the end of my script.

Mark Anthony,

Your script doesn't work if the Mail.app is running but user closed all viewers before running the script.
Last edited by KniazidisR (Today 09:05:58 am)

Last edited by KniazidisR (2020-11-20 09:16:55 am)


Model: MacBook Pro
OS X: Catalina 10.15.4
Web Browser: Safari 13.1
Ram: 4 GB

Offline

 

#8 2020-11-20 10:52:01 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5312

Re: Mail AppleScript opens viewer just fine but will not jump to Message 1

KniazidisR wrote:

The answer is coffin urine.


Please watch your language.

KniazidisR wrote:

Haste is only needed when catching fleas. You definitely substituted your own for my mailbox, or did you try to dig into mine? You should put into the code some real message existing in your Mail.app and not try to use my Mail.app....................................................


Since the OP's an obvious beginner and the  script they posted contains their own mailbox, it wouldn't hurt to use that instead of your own in your reply.


NG

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)