4 Replies Latest reply on Mar 14, 2014 8:38 AM by zeRafio

    Applescript: setting date for folder?

    ophello Level 1

      I have a script droplet for batch processing layouts and I have a part of the code that converts the date into a folder name.

       

      The problem is the date is output with one digit if it's a single-digit day. I need a zero before it.

       

      For example, a date of 3/6/14 goes through this part of the script:

       

                set shortDateString to short date string of (current date)

                set {oldTID, my text item delimiters} to {my text item delimiters, "/"}

                set dateBits to (text items of shortDateString)

                set my text item delimiters to ""

                set datePrefixString to (text item 3 of dateBits & text items 1 thru 2 of dateBits & "_Release") as text

                set my text item delimiters to oldTID

       

       

      And outputs this:

       

      1436_Release

       

      I need the output to be this:

       

      140306_release

       

      I can't figure it out -- your help is deeply appreciated!

        • 1. Re: Applescript: setting date for folder?
          Trevorׅ Adobe Community Professional

          I think you want something a bit more simple like

          set myDate to do shell script "date '+%y%m%d'" & "_release"

          HTH

          Trevor

          • 2. Re: Applescript: setting date for folder?
            Trevorׅ Adobe Community Professional

            This could be a long way which won't involve administrive rights issue's

             

            set yearstr to year of (current date) as string

            set yearstr to text -2 thru -1 of yearstr

             

            set monthnum to month of (current date) as integer

            if monthnum < 10 then

            set monthstr to "0" & (monthnum as string)

            else

            set monthstr to (monthnum as string)

            end if

             

            set daynum to (day of (current date)) as integer

            if daynum < 10 then

            set daystr to "0" & (daynum as string)

            else

            set daystr to (daynum as string)

            end if

             

            set myReleaseDate to yearstr & daystr & monthstr & "_release"

            • 3. Re: Applescript: setting date for folder?
              Trevorׅ Adobe Community Professional

              This would be a better way

               

              set myDate to (get current date)

               

              set y to year of myDate as text

              set d to day of myDate as integer

              set m to month of myDate as integer

               

              if d < 10 then

                  set d to "0" & d as text

              else

                  set d to d as text

              end if

               

              if m < 10 then

                  set m to "0" & m as text

              else

                  set m to m as text

              end if

               

              set y to text -2 thru -1 of y

               

              set myReleaseDate to y & d & m & "_release"

              • 4. Re: Applescript: setting date for folder?
                zeRafio Level 1

                For everyone who needs it in Applescript, this is a shorter way:

                 

                With hyphens and date in 4 digits

                 

                set a0 to short date string of (current date)
                
                set oldDelims to AppleScript's text item delimiters
                set AppleScript's text item delimiters to {"/"}
                set {a1, a2, a3} to text items of a0
                set AppleScript's text item delimiters to "-"
                set dateStamp to "20" & ({a3, a2, a1} as string)
                set AppleScript's text item delimiters to oldDelims
                

                 

                Without hyphens and date in 2 digits

                 

                set a0 to short date string of (current date)
                
                set oldDelims to AppleScript's text item delimiters
                set AppleScript's text item delimiters to {"/"}
                set {a1, a2, a3} to text items of a0
                set AppleScript's text item delimiters to oldDelims
                set dateStamp to ({a3, a2, a1} as string)