Updated Apple Mail Salutation Scripts

Hi Gang,

I’ve updated my email salutation script (and added a few more). Enjoy.

3 Likes

Love these - many thanks for the update @MacSparky.

One question, would it be possible to use Keyboard Maestro for the applescript and expansion combo, rather than doing the text-expansion part with Text Expander?

@revrob
That should absolutely work. I’m buried right now or I’d figure it out for you but KM can do text expansion and AppleScript, so you should be good.

This is by far my most used text expansion in Keyboard Maestro, thanks for the update.

1 Like

I just tested the new script that includes multiple recipients and it works perfectly in Keyboard Maestro.

Here’s a link to all my KM email scripts that I use, including the salutations and one that creates a link to the currently selected email in Mail (also inspired my MacSparky!). The xmhi one is for multiple recipients…

https://drive.google.com/file/d/1dZzNo_wXljqbE0X6zAjQh3om1aYhJlOk/view?usp=sharing

1 Like

Thank you very much. This is great!

Is the script still working for people using macOS 13.5? I am sure TextExpander was working fine previously and delivering the full salutation, now I just get “Hello”. I suspect this is something to do with Privacy and Security, but I have checked all through this. Any suggestions?

Hi Rob,

I was wondering if I could ask a favour - I’ve been trying to track down David Spark’s updated Salutation script for email and it looks like you might be someone who has it working. I wonder if you’d be kind enough to share the Keyboard Maestro macro again. The reason for going to you directly is that the various script download from David’s original blog post are coming up as dead links now (Improved AppleScript to Automatically Insert Recipient's Name in Apple Mail using TextExpander - MacSparky apple mail) and I can’t seem to find it anywhere else on the web or though other channels.

Sorry to bother you if you don’t still have it.

All the best

Rob

Here’s the latest version I have:

tell application "System Events"
    tell process "Mail"
        tell text field "To:" of window 1
            if UI element 1 exists then
                set theToRecipient to (value of UI element 1)
                if ((count words of theToRecipient) is greater than 0) and (theToRecipient does not contain ",") then
                    return word 1 of theToRecipient
                else if ((count words of theToRecipient) is greater than 0) and (theToRecipient contains ",") then
                    return word 2 of theToRecipient
                end if
            end if
        end tell
    end tell
end tell

I don’t use Mail anymore so I haven’t tested it in a few months.

Thanks Rob, that’s very kind of you to dig it out, much appreciated. If it’s not too cheeky to ask a quick follow up question - do you happen to know how a Keyboard Maestro might be configured to paste the result of this? If it’s run as Execute Applescript and the option to save results to System Clipboard is configured it doesn’t seem to produce a result. It may be I’m missing something obvious.

Cheers either way

Rob

I used this in TextExpander, and it consisted 2 snippets, one with the AppleScript and another to insert the snippet:

Thanks Rob, that’s very kind of you. That’s given me enough of a steer to get going with this. Thanks again for your generous assistance.

All the best

Rob