Create a default signature in the mail app with AppleScript

80 Views Asked by At

I tried to use this code:

tell application "Mail"
    set newSignatureContent to "Content of the new signature"
    set newSignatureName to "NewSignature"
    
    -- Create the signature
    set newSignature to make new signature with properties {content:newSignatureContent, name:newSignatureName}
    
    -- Set the signature as default for all existing accounts
    set allAccounts to every account
    repeat with currentAccount in allAccounts
        set signatures of currentAccount to {newSignature}
        set **default signature** of currentAccount to newSignature
    end repeat
end tell

but I get a Syntax Error. A class name cant go after this application constant or consideration and default signature is highleted, can you help me understand what is wrong here?

I tried to figure out a way to this coding the clicks on buttons but that's even more difficult and creates other problems.

1

There are 1 best solutions below

0
On BEST ANSWER
  1. Account's default (or selected) signature property doesn't exist.

  2. Exists Mail.app's selected signature property, which when setting to NAME of some signature, makes it selected (default) for IMAP accounts (such as "Gmail" account)

So, I am on Catalina. For my iCloud account following script doesn't work, but works for my Gmail account:

-- script: Create new Signature & make it default signature
-- tested: on Catalina
-- written: by me, right now

set newSignatureContent to "Content of the new signature"
set newSignatureName to "NewSignature"

tell application "Mail"
    activate
    
    -- Create the signature
    make new signature with properties {content:newSignatureContent, name:newSignatureName}
    
    -- Set default signature for my Gmail accounts to the NAME of created signature
    set selected signature to "NewSignature"
    
end tell

NOTE: you can set selected signature to constants randomly, sequentially, or none, as well.