Clicking items in apple mail preferences

Hi

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.

Thanks.

I do not use Apple Mail.

But it seems you can do it with an Run Applescript action.

I found this code:

    tell application "Mail"
       set enabled of account "NameOfAccount" to false
    end tell

on this site: http://www.mactech.com/articles/mactech/Vol.21/21.09/ScriptingMail/index.html

Try to set the name of account and the execute.
Change false to true to enable an account.

Unfortunately this note in the mactech.com article is true:

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 :heart_eyes:: When you re-launch Mail you always get back your default account selection.

(I always knew: Everything that Apple does makes sense. Somehow.)

Here is an extended version of @JimmyHartington’s script:

  • It shows you a list of all your accounts.
  • 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
1 Like