So you are zero-padding the month but not the day, just checking.
set monthDate to date (“” & “1-Jan-2004”) – any date within the month you want
set monthFolder to choose folder
set dayCount to daysInMonth(monthDate)
set nameList to ListIntegers(1, dayCount)
set monthAndYear to “-” & (“0” & (monthDate’s month as integer))'s ¬
text -2 thru -1 & “-” & monthDate’s year & return
set AppleScript’s text item delimiters to monthAndYear
set nameList to ((nameList as string) & monthAndYear)'s paragraphs 1 thru -2
set AppleScript’s text item delimiters to {“”}
tell application “Finder”
repeat with i from 1 to nameList’s length
make new folder at (monthFolder) with properties {name:nameList’s item i}
end repeat
end tell
on ListIntegers(x, y)
if (x = y) then return {x}
set a to {}
repeat with i from x to y
set a’s end to i
end repeat
repeat with i from x to y by -1
set a’s end to i
end repeat
return a
end ListIntegers
on daysInMonth(theDate) – courtesy of Nigel Garvey
copy theDate to d
set d’s day to 32
return 32 - (d’s day)
end daysInMonth
Thank you for your response!
Your script works fluently, but it is bit too complicated for me to understand exactly what is going on it,
so I decided to stick with this simpler one which I find easier to modify.
Yeah, it’s fast but not intuative, (but then again, using ‘do shell script’ is a bit too complicated for me).
I should have provided better comments in any case:
-- Set to any date within the target month:
--
set monthDate to date ("" & "1-May-2004")
-- Where are we putting the new folders:
--
set monthFolder to choose folder
-- This is a wonderful handler of Nigel Garvey's. It uses his
-- custom "overflow" method to determine the last day
-- in a month:
--
set dayCount to daysInMonth(monthDate) -- 28, 29, 30, or 31
-- Knowing how many days this month has, we generate
-- a list of integers from 1 to the last day:
--
set nameList to ListIntegers(1, dayCount) -- {1, 2, ..., 30, 31}
-- What then follows is a text item delimiter technique for inserting
-- a string between those integers:
--
set monthAndYear to "-" & ("0" & (monthDate's month as integer))'s ¬
text -2 thru -1 & "-" & monthDate's year & return
--
--> "-05-2004r" we use the line-end to break the string back into a list
set AppleScript's text item delimiters to monthAndYear
set nameList to ((nameList as string) & monthAndYear)'s paragraphs 1 thru -2
--
--> {"1-05-2004", "2-05-2004", etc...}
set AppleScript's text item delimiters to {""} -- restore
tell application "Finder"
-- Just go thru the list of pre-generated names and make
-- folders for them:
--
repeat with i from 1 to nameList's length
make new folder at (monthFolder) with properties {name:nameList's item i}
end repeat
end tell
on ListIntegers(x, y)
if (x = y) then return {x} -- list of one integer
set a to {} -- collect the integers
-- only one of these two repeats will loop:
repeat with i from x to y -- x < y
set a's end to i
end repeat
repeat with i from x to y by -1-- x > y
set a's end to i
end repeat
return a
end ListIntegers
on daysInMonth(theDate) -- courtesy of Nigel Garvey
copy theDate to d
-- As Nigel says, "whose writing this AppleScript language anyway?" ;-)
--
set d's day to 32
return 32 - (d's day)
end daysInMonth