I’d like to disable one of my email accounts at various times in apple mail. Wondering if there’s a way to do this via KM.
My current process is: launch apple mail, type command-, to go to preferences, click Accounts, find the right account from the left hand side panel and untick Enable this account.
It is important to note that, when disabling account with AppleScript, the account will automatically become re-enabled the next time Mail is launched.
Does anybody know a way to make it persistent?
PS:
Maybe, to make it persistent, we would have to speak to Internet Accounts (in System Preferences)? But that one seems to be accessible only via UI scripting.
Anyway, after thinking about it, I came to the conclusion that actually it is a feature: When you re-launch Mail you always get back your default account selection.
(I always knew: Everything that Apple does makes sense. Somehow.)
Enabled accounts are selected, disabled accounts are unselected.
Select an account to enable it.
Deselect an account to disable it.
As usual, hold ⌘ or ⇧ for multiple (de)selections.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
tell application "Mail"
set enabledAccounts to {}
set allAccounts to name of every account
repeat with theAccount in allAccounts
if enabled of account theAccount is true then set end of enabledAccounts to contents of theAccount
end repeat
end tell
tell application (path to frontmost application as text)
set selectedAccounts to choose from list allAccounts with title "Mail Accounts" with prompt "Select to enable, deselect to disable account." & return & "Hold ⌘ or ⇧ to (de)select multiple accounts." OK button name "OK" cancel button name "Cancel" default items enabledAccounts multiple selections allowed yes empty selection allowed no
if selectedAccounts is false then error number -128
end tell
tell application "Mail"
repeat with theAccount in allAccounts
if name of account theAccount is in selectedAccounts then
set enabled of account theAccount to true
else
set enabled of account theAccount to false
end if
end repeat
end tell