Birthday Emails

Since this is such an uncommon occurrence, I’d suggest that you two trade email addresses in a direct message (click your avatar in the upper right, click the envelope icon twice, and create a new message) and then share it out-of-band.

Thanks. That is what we have done.

1 Like

That’s exactly what we did, but @jajvj1 beat me to posting it. :wink:

1 Like

@jajvj1 @angusC @Shamino
You’ve convinced me to sally forth to give AppleScript a try. Other than installing Script Debugger, do you have any other suggestions for getting started?

I found these forums for AppleScript:

Do you recommend any one of these over another? Or, something else that I haven’t found?

Thank you.

Yes, correct. It is a Custom Label that I use on a Date field.

Yes, creating a draft email would be fine.

But, I don’t use a Mac application for email; I use (the web interface to) Gmail. (On iOS I use Spark.) So, ideally, I’d prefer the draft to be created in my Gmail Drafts folder. I’m guessing that doing so directly would require the script to run on Google’s server and that looks hard to do.

Since I’ve set Gmail as my default mailer on macOS, I’m wondering whether I can get an unattended AppleScript on macOS (triggered by a custom launch daemon, as suggested by @Shamino) to open a draft email in Gmail using a mailto: link. Any thoughts?

I looked at Flexibits’ help page and the macOS version of Fantastical appears to support AppleScript, but I didn’t see any indication that AppleScript can run a date query that returns a list of matches. Its iOS FAQ says that Fantastical supports an x-callback-url but the macOS FAQ makes no mention of such support. (Moreover, the list of applications supporting x-callback-url points to the iOS app alone, not the macOS version.)

So, the bottom line is that Fantastical running on macOS doesn’t look promising, as far as I can see. I’m not aware of anyway to execute an AppleScript on iOS (though apparently an iOS Shortcut can can invoke an AppleScript on macOS and return data as a JSON string). So, I don’t know how I could make use of support for x-callback-url on the iOS verson of Fantastical.

Of course, I suppose that I could use an iOS automation Shortcut to trigger Scriptable to (1) query iOS Fantastical using an x-callback-url, and (2) uses uses each resulting match to create a iOS Spark draft via a mailto: URL scheme. (Sounds rather like a Rube Goldberg Machine to me; surely there is a more straightforward way to accomplish what I want.)

As an aside, I can NOT find a x-callback-url for Apple’s iOS Calendar app.

Please let me know if you see something that I overlooked.

Thank you.

The first three (Stack Overflow, Ask Different and Super User) are all part of the Stack Exchange network. These are really meant for specific questions to solve specific problems (for software development, Macs and system administration, respectively). They are not really appropriate for tutorial type questions about how to get stating with programming in general.

The MacScripter site looks like it might be promising. They have a tutorial section of the forums.

A web search found this Apple forum post: Starting out with AppleScript - Apple Community

It contains references and links to various books and resources you may find useful.

1 Like

@jajvj1 @angusC @Shamino
It turns out that this script is simplified tremendously by using the appropriate SmartGroup.

UPDATE: March 5, 2024 9:54 AM

Unfortunately, this SmartGroup stopped working at about the time of this year’s leap day, February 29, as I posted in:

  1. TidBITS Talk Topic
  2. Late Night Software Topic
  3. Apple Community Discussion Topic

Rebuilding the Spotlight index help but it still isn’t working as well as before the leap day.

Does anyone else have any ideas how to get this SmartGroup working again:

Birthday Soon
Birthday is in the next 1 day

Thank you.

1 Like

Just getting caught up on this, so sorry if you’re already solved this.

Using gmail through a web browser might not work, but it would be pretty trivial to set up Apple Mail to link to the gmail account, or some other local client that supports AppleScript…you only need the most basic of functionality to create some draft messages. If it’s not your main mail client, you might even be able to have it not download mail automatically, so when the AppleScript opens the mail client, it just creates the draft messages, saves them to the server, and quits. That’s all supposition though.

Creating the draft messages would be very straight forward AppleScript though.

I’m making great progress on a solution that uses AppleScript to create a separate mailto: URL string for each draft email birthday (and anniversary) greeting. The advantage of this approach is that it uses your mailer of choice and, in my case, opens Gmail drafts in my browser.

That’s great, wasn’t sure that would work, but thought there was a chance.

Loved the smart groups in contacts too.

@Shamino @jajvj1 @angusC @macguyver
I posted a working AppleScript.

Any idea why open location doesn’t encode the emoji correctly?

If I need to use a shell script, would someone please provide a snippet or link to some examples?

Thank you.

UPDATE: June 5, 2022 4:35 PM
I changed the link to my script.

Apparently, there are at least two applications for doing this:

Do you recommend either of them or should I just create the launchd plist file with a text editor manually?

UPDATE: June 5, 2022 4:24 PM
Corrected link to LaunchControl

Personally, I like LaunchControl better. It’s free and does a lot of error detection and some corrections for you (even finds errors in Apple launch items). Lots of help to explain various functional areas.

1 Like

Thank you for your input, but LaunchControl doesn’t NOT appear to be free; it looks like it costs $18 for a Personal License.

Am I misunderstanding something?

1 Like

As I understand, open location automatically encodes UTF-8 characters appropriately but Emoji characters are NOT encoded correctly by AppleScript per se.

I tried encoding the Emoji balloon character (“:balloon:”) using Online Text Tools and the character was simply ignored.

Apparently, Emoji encoding should be done via:

  • ASObjC
  • Shell command to Perl, Python (somewhat more involved since Apple no longer installs Python with macOS), etc.
  • JXA

Do you have any advice on which to choose?

I’ve never used either of these. My personal opinion is that the plist file format is simple enough that I’d just write my own (possibly looking at some created by other apps as references).

Plist files can be in XML format (where you can just rename a text file) or a binary format. Apple’s Xcode environment includes a general-purpose Plist editor which can work on either format. I’d recommend using the XML format, simply because it’s easier to maintain, but the Xcode editor may come in handy if you want to view plists created by other apps, which often use the binary format.

I’m afraid I can’t help here. I just looked up some useful articles and shared the links I found. I haven’t actually tried doing this.

Since you’re probably looking to just make one-time conversions (to create boilerplate text), I’d just try them all, starting from the easiest ones, until you find something that works for you.

Sorry, I had forgotten that I did pay $10 for it back in 2016. Comes with age, I guess.

Personally, I would not recommend creating a launchd plist file manually, even if duplicating and editing an existing one. I did this a few times early on in launchd’s history, and it works… but the launchd plist format can be inscrutable. It has so many options and potential keys you can use, that when looking for an existing plist file to copy you’ll find different developers achieving essentially the same thing in different ways. At the time, it was also poorly documented, which might still be the case! So for many years my preference has been to use Lingon X or LaunchControl as it’s much easier to see the options you can set, get explanations, and edit your launchd file in a structured way. Even when I duplicate an existing launchd plist file as a starting point, I use LaunchControl to edit it.

At first I used Lingon (I think it was the only option back then) but some years ago I switched to LaunchControl. I can’t remember why. I think both are good – they’ve got quite different approaches so it will mainly be a question of which style fits your way of thinking/working best. Both have free trials so you can play about a bit and see which suits.

BBEdit (which has a free ‘Lite’ version too) can also edit binary plist files. If you don’t have Xcode installed already, I would recommend this as it is more lightweight (quicker to load, responsive, and generally excellent as a text editor) and a much smaller download!

This thread offers many suggestions for encoding emoji characters.

Ultimately, I settled on using the percent encode handler within Shane Stanley’s RegexAndStuffLib v1.0.7 AppleScript Library. This and other useful libraries can be downloaded from Late Night Software’s freeware collection.

1 Like

I got my (first) AppleScript applet working. :partying_face:

Thank you to everyone who helped me along the way, including without limitation: @jzw @Shamino @alvarnell @angusC @jajvj1.

My script scans Contacts for people who have a birthday and/or wedding anniversary on the day it’s run and drafts a simple email greeting in the default mailer—mine is the web interface to Gmail—that can be edited prior to sending (manually). I’ve included code to automatically send greetings by SMS if a suitably labeled email address isn’t available. But I commented out the actual SMS sending because I’m not comfortable letting any greeting go out automatically without a manual review.

It’s reasonably well documented and includes switches for some limited logging and tracing.

My early versions ran in less than 3 seconds. After taking a close look at my Contacts, however, I added some unnecessary data checking and logging to help me identify cleanup opportunities; now it takes about 7 seconds to run through my 6K of Contacts on my ancient iMac (late 2015?).

Please private message me if you’d like a copy of the script file to play with and make your own.

For the lawyers …

THIS OFFER EXCLUDES ALL WARRANTIES OR GUARANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, TITLE AND FITNESS FOR A PARTICULAR PURPOSE.

4 Likes