Re: How to create a Calendar event on a specific day of next month?
Re: How to create a Calendar event on a specific day of next month?
- Subject: Re: How to create a Calendar event on a specific day of next month?
- From: Jim Krenz via AppleScript-Users <email@hidden>
- Date: Sat, 19 Jun 2021 17:04:51 -0700
Thank you Jim! Very helpful resource!
With Jim’s and Christopher Stone’s help on the LNS forum, I have a working
script. Posting it here, in case it helps anyone else:
tell (current date)
set its month to (its month) + 1
set its day to 18
set its hours to 14
set its minutes to 0
set its seconds to 0
set theStartDate to it
set theEndDate to theStartDate + (3 * hours)
tell application "Calendar"
tell calendar "Home"
set newEvent to make new event at end with properties
{summary:"Rent is due", location:"Venmo", allday event:true, start
date:theStartDate, end date:theEndDate, description:"This is your courtesy
reminder to pay your rent.", url:"https://venmo.com/account/sign-in"}
tell newEvent
make new sound alarm at end of sound alarms
with properties {trigger interval:840, sound name:"Crystal"}
make new sound alarm at end of sound alarms
with properties {trigger interval:-120, sound name:"Crystal"}
make new sound alarm at end of sound alarms
with properties {trigger interval:-10200, sound name:"Crystal"}
end tell
end tell
end tell
end tell
Many thanks to Jim & Christopher!
Sincerely,
Jim
> On Jun 19, 2021, at 4:13pm, Jim Underwood via AppleScript-Users
> <email@hidden> wrote:
>
> Hi Jim,
>
> Manipulating dates in AppleScript is one of the most frustrating tasks there
> is, especially if you are familiar with other languages that have rich date
> functions built in.
>
> IAC, I hope you'll find this helpful.
>
> First, here's a great date resource:
> Dates & Times in AppleScripts -- MacScripter Adam Bell et al
> <https://macscripter.net/viewtopic.php?id=24737>
>
> I actually reviewed that again, but did not find a concise solution to your
> problem, but I may have missed it since there is so much there. I'm sure
> that Nigel Garvey will jump in if it missed it, or there is a better method.
>
>
> So, here is what I came up with, based in part on the MacScripter's scripts
> --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> property ptyScriptName : "Get Next Month Same Day"
> property ptyScriptVer : "1.0"
> property ptyScriptDate : "2021-06-19"
> property ptyScriptAuthor : "JMichaelTX"
>
> (*
> REF: Dates & Times in AppleScripts -- MacScripter/Adam Bell et al
> https://macscripter.net/viewtopic.php?id=24737
> <https://macscripter.net/viewtopic.php?id=24737>)
> 2007-07-23
> *)
>
> set startDate to (current date)
> set {month:m, day:d, year:y} to startDate
>
> copy startDate to nextMonth
>
> --- Set to Next Month After StartDate ---
> set nextMonth's day to 32
>
> --- Set to the Month After Next Month --
> set nextMonth's day to 32
> set manmDay to day of nextMonth
>
> --- Now Set Back to Last Day of Next Month ---
> set nextMonth to nextMonth - (manmDay * days)
> set lastDay to day of nextMonth
>
> --- Finally Set the Day of Next Month, but no later than it's last day ---
> if (d ≤ lastDay) then
> set nextMonth's day to d
> end if
>
> return nextMonth
>
> -->date "Monday, July 19, 2021 at 6:04:51 PM"
> --~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
>
> Best Regards,
>
> Jim Underwood
> aka JMichaelTX
>
>
>
> From: "ASUL (AppleScript)" <email@hidden
> <mailto:email@hidden>>
> Reply-To: Jim Krenz <email@hidden <mailto:email@hidden>>
> Date: Saturday, June 19, 2021 at 3:24 PM
> To: "ASUL (AppleScript)" <email@hidden
> <mailto:email@hidden>>
> Subject: How to create a Calendar event on a specific day of next month?
>
> Hello all,
>
> I am trying to create a Calendar event on a specific day of next month (the
> 18th, in this case).
>
> I am using this workaround, as I generally create the event a month in
> advance:
>
> set theStartDate to (current date) + (30 * days)
>
> But due to months having different quantities of days (or the day that I
> execute the script), the event may be created on the wrong day.
>
> Here is the draft of the entire script:
>
> set theStartDate to (current date) + (30 * days)
> set hours of theStartDate to 14
> set minutes of theStartDate to 0
> set seconds of theStartDate to 0
> set theEndDate to theStartDate + (3 * hours)
> tell application "Calendar"
> tell calendar "Home"
> set newEvent to make new event at end with properties {summary:”Rent is due",
> location:"Venmo",allday event:true, start date:theStartDate, end
> date:theEndDate, description:"This is your courtesy reminder to pay your
> rent.", url:"https://venmo.com/account/sign-in
> <https://venmo.com/account/sign-in>"}
> tell newEvent
> make new sound alarm at end of sound alarms with properties {trigger
> interval:840, sound name:"Crystal"}
> make new sound alarm at end of sound alarms with properties {trigger
> interval:-120, sound name:"Crystal"}
> make new sound alarm at end of sound alarms with properties {trigger
> interval:-10200, sound name:"Crystal"}
> end tell
> end tell
> end tell
>
> Thanks for any help!
>
> Sincerely,
>
> Jim
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> AppleScript-Users mailing list (email@hidden
> <mailto:email@hidden>)
> Help/Unsubscribe/Update your Subscription:
>
> Archives: http://lists.apple.com/archives/applescript-users
> <http://lists.apple.com/archives/applescript-users>
>
> This email sent to email@hidden <mailto:email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden