Applescript: First day of month (or last)

Discussion in 'Mac Programming' started by jbsmithmac, Feb 19, 2014.

  1. jbsmithmac macrumors regular

    Joined:
    Sep 11, 2011
    #1
    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
     
  2. jbsmithmac thread starter macrumors regular

    Joined:
    Sep 11, 2011
    #2
    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
    
     
  3. ytk macrumors regular

    Joined:
    Jul 8, 2010
    #3
    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)"
     
  4. ssls6 macrumors 6502a

    ssls6

    Joined:
    Feb 7, 2013
    #4

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

Share This Page