简体   繁体   中英

AppleScript change Outlook signature

I wrote an application for my colleagues so that they can easily set their Outlook signature. Here is the code:

property includeInRandom : false
property sigName : "${signature.name}"
property sigContent : "${signature.content}"

try
tell application "Microsoft Outlook"
    activate
    set newOutlookSignature to make new signature with properties ¬
    {name:sigName, content:sigContent, include in random:includeInRandom}
end tell
end try

The problem is that if a colleague changes his signature in the application and sets it in Outlook again there are two signatures with the same name. Is it possible to check if the current signature already exists and if it exists it should be edited/updated?

I don't have Microsoft Outlook , so I can't test my suggestions out, but I imagine you could get every signature whose name is sigName , then decide if you want to just delete them all and make a new one, or keep one, edit it, and delete the rest. I'm obviously working on the assumption there could be anywhere between 0 and N signatures sharing one name that have accumulated over time. From this standpoint, I'd say that deleting them all and making new one would be easiest coding wise, provided Outlook lets you delete a list of signatures the way, say, Finder lets you delete a list of files in a single command:

tell application "Microsoft Outlook" to delete every signature whose name is sigName

If it doesn't, you would have to construct a repeat loop and delete them one by one:

tell application "Microsoft Outlook" to repeat with S in ¬
    (every signature whose name is sigName)
    set S to the contents of S  # (dereferencing)
    delete S
end repeat

If you decide you want to keep one and edit it, then:

tell application "Microsoft Outlook"
    set S to every signature whose name is sigName

    if (count S) is 0 then
        # make new signature
    else
        set [R] to S
        delete the rest of S
        set the content of R to the sigContent
    end if
end tell

If delete the rest of S doesn't work, a repeat loop again will let you delete items 2 onwards individually, and keep just the first item to edit.

I'm sorry I can't test this for you, but it's at least an indication of how to go about trying to do it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM