thomasleplus / google-apps-scripts

A collection of useful Google Apps Scripts.
Apache License 2.0
14 stars 2 forks source link

[FEAT] Optional Subject Title Prefix #6

Closed bonelifer closed 1 year ago

bonelifer commented 1 year ago

Feature description Add a script property that if it exists, then the script take it's contents and adds them as a prefix to the subject title. In my case still using this for my doctors appointments case, it'd be nice to be able to tell the difference between the twelve day email(for scheduling ride to doctors, I'd leave it blank here, it'd look like usual) and the reminder that I have an appointment the next day(I'd fill it in with what ever text I want to differentiate it from the 12 day notice) .

thomasleplus commented 1 year ago

Just to confirm that I get this right, you have the script configured twice on the same calendar: one with a 12-day offset and one with a 1-day offset. And you'd like to have a different prefix in each case to be able to differentiate the emails coming from each script. Is that right?

bonelifer commented 1 year ago

Currently only 12 days. But basically yes. If subjTitlePrefix isn't null, then "subjTitlePrefix + title", else if it is null then just leave it as "title". Needles to say, I tend to forget to warn my brother-in-law that I have an appointment the day before and he needs to move some stuff so I can get myself out without help.,

thomasleplus commented 1 year ago

Got it. I have made the change in this branch: https://github.com/thomasleplus/google-apps-scripts/blob/6-feat-optional-subject-title-prefix/birthday-reminders/Code.gs

I have added 2 properties, one called 'prefix' and the other 'suffix' (maybe someone will need it). I tested that the code works like before for me my use case (birthday reminders) but if since you have the setup with two calendars etc., would you mind testing that it works for you too with the prefix?

Once you confirm I will merge the change to master to make it 'official'.

bonelifer commented 1 year ago

Works, tried both. Would note that Google removes trailing space, so there is no space between the prefix and title, because of this. I got around it by using: https://www.compart.com/en/unicode/U+2800

Though I'm using it on one calender. Same calendar entry. One use of the script to remind me twelve days before so I can arrange pickup. Using prefix in the run to remind me to tell my b-i-l to move stuff, so I can get out for my appointment after he's went back to sleep. This way I don't ignore it thinking it's the email from the twelve day reminder. Also thanks, for the helping me.

thomasleplus commented 1 year ago

The issue that you found regarding Google removing trailing spaces bothers me a bit. You found a clever workaround but it feels like there should be a simpler solution. I'll see if I can find a better design.

thomasleplus commented 1 year ago

I think that I have found a better solution. The new code is at the same URL: https://github.com/thomasleplus/google-apps-scripts/blob/6-feat-optional-subject-title-prefix/birthday-reminders/Code.gs

In your case, I think that this code should work if you create a new property named "emailSubjectTemplate" and with a value of let's say "${properties.prefix} ${event.getTitle()}" to say that you want to put in the email subject first the value of the "prefix" property, then a space, then finally the event's title.

Note that you could also remove the "prefix" property completely and hard-code the prefix in "emailSubjectTemplate", e.g. "12 days notice: ${event.getTitle()}".

Or even better (maybe), you could inject the "offset" property value in the subject directly, e.g. "${properties.offset} days notice: ${event.getTitle()}", this way if you ever change the value from 12 to something else, it will automatically reflect in the subject with needing to change the "emailSubjectTemplate".

Let me know if it works for you.