Re: How do I use if/then with this Apple Mail script?
Re: How do I use if/then with this Apple Mail script?
- Subject: Re: How do I use if/then with this Apple Mail script?
- From: Jim Krenz via AppleScript-Users <email@hidden>
- Date: Sat, 18 Apr 2020 16:54:11 -0700
Hello all!
I wanted to follow up and share my final solution, which I am quite happy with.
Thank you to everyone who helped—without your input, I would not have figured
out my script.
The original goal:
> To cycle through my chosen mailboxes when I trigger the script.
if/else is what I needed to pursue.
For this to work, you will need to replace the X# with the names of your
accounts. And of course, you can adjust the length of the script if you have a
different number of mailboxes that you wish to cycle through.
tell application "Mail"
if name of message viewer 1 contains “X1" then
set selected mailboxes of message viewer 1 to mailbox "INBOX"
of account “X2"
else
if name of message viewer 1 contains “X2" then
set selected mailboxes of message viewer 1 to mailbox
"INBOX" of account “X3"
else
if name of message viewer 1 contains “X3" then
set selected mailboxes of message viewer 1 to
mailbox "INBOX" of account “X4"
else
if name of message viewer 1 contains “X4" then
set selected mailboxes of message
viewer 1 to mailbox "INBOX" of account “X5"
else
if name of message viewer 1 contains
“X5" then
set selected mailboxes of
message viewer 1 to mailbox "INBOX" of account “X6"
else
if name of message viewer 1
contains “X6" then
set selected mailboxes
of message viewer 1 to mailbox "INBOX" of account “X7"
else
if name of message
viewer 1 contains “X7" then
set selected
mailboxes of message viewer 1 to mailbox "INBOX" of account “X8"
else
if name of
message viewer 1 contains “X8" then
set
selected mailboxes of message viewer 1 to junk mailbox
else
if name
of message viewer 1 contains "Junk" then
set selected mailboxes of message viewer 1 to trash mailbox
else
if name of message viewer 1 contains "Trash" then
set selected mailboxes of message viewer 1 to mailbox "INBOX" of
account “X1"
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
end tell
I wanted to post this, on the chance that it helps someone in the future.
Thanks again to all of you! The various advice and examples from the list truly
helped!
Sincerely,
Jim
> On Jan 12, 2020, at 10:42 pm, Jim Krenz <email@hidden> wrote:
>
> That works! Thank you Takaaki!
>
>> On Jan 12, 2020, at 10:14 pm, Takaaki Naganoya <email@hidden> wrote:
>>
>> Hi Jim,
>>
>> Hmm.... I encountered with same inheritance on my macOS 10.15.2 environment.
>>
>> "whose enabled is true" is for just in case of the existence of some unused
>> mail account.
>> So, basically there is no need to write it.
>>
>> Try this.
>>
>>
>> Takaaki Naganoya
>>
>> <AppleScript>
>> tell application "Mail"
>> set aList to id of every account
>>
>> repeat with i in aList
>> set aMB to mailbox "INBOX" of account id i
>>
>> set aMV to make new message viewer
>> tell aMV
>> set selected mailboxes to aMB
>> end tell
>> end repeat
>>
>> end tell
>> </AppleScript>
>>
>>
>>> 2020/01/13 14:57、Jim Krenz <email@hidden>のメール:
>>>
>>> Hello Takaaki,
>>>
>>> I am using Catalina, version 10.15.2 (19C57) with Mail 13.0
>>> (3608.40.2.2.4). Maybe that i the issue?
>>>
>>> This is highlighted from the error: id of every account whose enabled is
>>> true
>>>
>>> When I run the script at the end of your last message (I presume that it is
>>> for troubleshooting), I get this result:
>>>
>>> {{-10000, "AppleEvent handler failed."}}
>>>
>>> Sincerely,
>>>
>>> Jim
>>>
>>>> On Jan 12, 2020, at 9:45 pm, Takaaki Naganoya <email@hidden> wrote:
>>>>
>>>> Hi Jim,
>>>>
>>>> I wrote & checked this script with macOS 10.14.6 + Mail.app v12.4.
>>>> Classical layout and current layout are both OK.
>>>>
>>>> My Mail.app hosts 8 mail accounts and returns no error.
>>>>
>>>> Which version of macOS do you use?
>>>>
>>>> And...which line causes the error?
>>>>
>>>> -10000 error is "The Apple event handler failed." I think something wrong
>>>> with your script (copy & paste miss-operation may be possible....)
>>>>
>>>>
>>>> Takaaki Naganoya
>>>>
>>>>
>>>> <AppleScript>
>>>> set erList to {"-10000"}
>>>>
>>>> set mesList to {}
>>>>
>>>> repeat with i in erList
>>>> set j to contents of i
>>>> set {aNum, aMes} to errorGenerator(j) of me
>>>> set the end of mesList to {aNum, aMes}
>>>> end repeat
>>>>
>>>> mesList
>>>> --> {{-10000, "The Apple event handler failed."}}
>>>>
>>>> on errorGenerator(aNum as number)
>>>> set handlerName to "errorGenerator"
>>>> try
>>>> error number aNum
>>>> on error errMsg number ErrNbr partial result partialResult from from_
>>>> to to_
>>>> return {ErrNbr, errMsg}
>>>> end try
>>>> end errorGenerator
>>>> </AppleScript>
>>>>
>>>>
>>>>> 2020/01/13 13:53、Jim Krenz <email@hidden>のメール:
>>>>>
>>>>> Interesting approach. I’m will to try it to see if my workflow habits can
>>>>> adapt to multiple viewer windows.
>>>>>
>>>>> That said, the i run the script, I get this error:
>>>>>
>>>>> error "Mail got an error: AppleEvent handler failed." number -10000
>>>>>
>>>>> Jim
>>>>>
>>>>>> On Jan 12, 2020, at 8:30 pm, Takaaki Naganoya <email@hidden>
>>>>>> wrote:
>>>>>>
>>>>>> You can make new message viewer windows with each different target
>>>>>> account.
>>>>>> You can choose target account INBOX by choosing message viewer window.
>>>>>>
>>>>>>
>>>>>> <AppleScript>
>>>>>> tell application "Mail"
>>>>>> set aList to id of every account whose enabled is true
>>>>>>
>>>>>> repeat with i in aList
>>>>>> set aMB to mailbox "INBOX" of account id i
>>>>>>
>>>>>> set aMV to make new message viewer
>>>>>> tell aMV
>>>>>> set selected mailboxes to aMB
>>>>>> end tell
>>>>>> end repeat
>>>>>>
>>>>>> end tell
>>>>>> </AppleScript>
>>>>>>
>>>>>> Takaaki Naganoya
>>>>>>
>>>>>>
>>>>>>> 2020/01/12 8:26、Jim Krenz via AppleScript-Users
>>>>>>> <email@hidden>のメール:
>>>>>>>
>>>>>>> Hello all,
>>>>>>>
>>>>>>> I have made this simple script to go to a specified Mail inbox:
>>>>>>>
>>>>>>> tell application "Mail"
>>>>>>> set selected mailboxes of message viewer 1 to mailbox "INBOX"
>>>>>>> of account “Nostravinci"
>>>>>>> end tell
>>>>>>>
>>>>>>> What I want to create, is a script that will go to my first inbox, and
>>>>>>> when triggered again, go to my second mailbox, and so on.
>>>>>>>
>>>>>>> I think this can be accomplished with if/then, but if/then mystifies me.
>>>>>>>
>>>>>>> Does anyone have any advice or examples that would help me?
>>>>>>>
>>>>>>> Thanks!
>>>>>>>
>>>>>>> Jim
>>>>>>> _______________________________________________
>>>>>>> Do not post admin requests to the list. They will be ignored.
>>>>>>> AppleScript-Users mailing list (email@hidden)
>>>>>>> Help/Unsubscribe/Update your Subscription:
>>>>>>> Archives: http://lists.apple.com/archives/applescript-users
>>>>>>>
>>>>>>> This email sent to email@hidden
>>>>>>
>>>>>> --
>>>>>> Takaaki Naganoya
>>>>>> email@hidden
>>>>>> http://piyocast.com/as/
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>>
>>>> --
>>>> Takaaki Naganoya
>>>> email@hidden
>>>> http://piyocast.com/as/
>>>>
>>>>
>>>>
>>>
>>
>> --
>> Takaaki Naganoya
>> email@hidden
>> http://piyocast.com/as/
>>
>>
>>
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden