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: Andrew Oliver via AppleScript-Users <email@hidden>
- Date: Sat, 11 Jan 2020 21:45:22 -0800
The fact that you want it to do something different on each invocation means
that you have to maintain state - in other words, you have to somewhere record
what the ‘last’ action was so that you know what to do next time.
That’s more than a if/then clause.
It’s also complicated by the fact that the ’next mailbox’ is vague.
As a simplified solution I’d start with a simple indexing… from 1 to the number
of mailboxes in the account.
For each invocation, record the number of the mailbox just processed. Then when
you start, increment that number and process as required:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property MailboxIndex : 0
tell application "Mail"
-- increment the counter
set MailboxIndex to MailboxIndex + 1
if MailboxIndex > (count mailboxes of account "iCloud") then set
MailboxIndex to 1
set selected mailboxes of message viewer 1 to mailbox MailboxIndex of
account "iCloud"
end tell
Here I use a simple counter - initially set to 0. For each invocation I add
one, then check if that exceeds the number of mailboxes for the account. If it
does I reset the counter to the first inbox. Then I tell mail to display the
current index.
HTH
Andrew
> On Jan 11, 2020, at 3:26 PM, Jim Krenz via AppleScript-Users
> <email@hidden> wrote:
>
> 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
_______________________________________________
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