Mac Applescript: First day of month (or last)

jbsmithmac

macrumors regular
Original poster
Sep 11, 2011
243
0
Hi,
I'm new to applescript and I'd like to do something specific on the first (or last) day of the month.

So how do I write something like:
If current date is "first day of the month" Then do XYZ
 

jbsmithmac

macrumors regular
Original poster
Sep 11, 2011
243
0
incase anyone else happens to be searching for this one day…I figured it out.

Basically I needed my script to do something different once a month - it could have been any day of the month, it didn't really matter.

Being that for most months there are a number of days that exist for each month (the 1st of each month, 2nd 3rd, etc.) but not every month has a 31st, so if you can get away with out needing the last day then this would work (or you could do something like the 1st - 1 day)

Anyway here's what I did…pretty simple. This only runs on the 1st of each month.

Code:
set myday to day of (current date)
     if myday = 1 then
     do whatever you need here
end if
 

ytk

macrumors regular
Jul 8, 2010
219
0
You could use the same technique to run on the last day of the month as well, if you really had to do that for some reason. You can add seconds to "current date", so just change the first line to "set myday to day of ((current date) + 86400)"
 

ssls6

macrumors 6502a
Feb 7, 2013
535
144
Hi,
I'm new to applescript and I'd like to do something specific on the first (or last) day of the month.

So how do I write something like:
If current date is "first day of the month" Then do XYZ

Automator is what you want. Create a new calendar event and go from there.