« Rotate portrait pages by 90 degrees in a PDF | Main | OCR all PDF files in a directory using PDFpenPro 6 »

Formatting short dates in AppleScript

I was updating some AppleScripts that need the current date as a string in my preferred format (YYYY-MM-DD). The way I've typically done this is to paste the following function in and call it:

    on todayISOformat() 
        set theDate to current date
        set y to text -4 thru -1 of ("0000" & (year of theDate))
        set m to text -2 thru -1 of ("00" & ((month of theDate) as integer))
        set d to text -2 thru -1 of ("00" & (day of theDate))
        return y & "-" & m & "-" & d
    end todayISOformat

For quick and dirty scripts that are only going to run on your own computer I realized there's a cleaner way to get it: reset your system's standard for the format of Short Date to be YYYY-MM-DD (vs. the default MM/DD/YY) and then in AppleScript call:

    short date string of (get current date)