I am trying to modify a script that created daily publication folders based on a selected month. I would now like to create a years worth of monthly folders and daily subfolders based on a selected year.
And here is what I have created thus far for my new script.
property theMonths : {"JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC"}
property theWeekdays : {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}
set destinationFolder to choose folder with prompt "Choose destination folder"
(* Choose destination folder for script to create folders inside of *)
tell (current date) to set thisMonth to (it - (its day) * days + days - (its time))
(* Set variable thismonth to first day of month *)
tell (current date) to set thisyear to its year
(* set variable this year to current year *)
set yearlist to {} (* Create empty year list *)
repeat with i from 1 to 11
set end of yearlist to (thisyear + i - 6) as string
end repeat
(* Fill year list with the previous 5 years followed by the next 5 *)
set chosenyear to (choose from list yearlist with prompt "choose a year") as string
if chosenyear is "false" then return
(* set vaiable choosenyear to year picked from menu*)
set FMonth to January as integer
(* set variable thismonth to January as integer*)
set curFmonth to January of chosenyear
(* set variable thismonth to January of selected year*)
display dialog curFmonth as string buttons {"OK"} default button 1
repeat with eachmonth from 0 to 11
if FMonth ≤ 12 then
set m to item (FMonth) of theMonths
set folderName1 to text -2 thru -1 of ("0" & FMonth) & space & m
try
tell application "Finder"
set folderName1 to make new folder at destinationFolder with properties {name:folderName1}
(* Create folder for each month in year *)
tell curFmonth to tell it + 32 * days to set lastDate to day of (it - (its day) * days + 86399)
repeat with oneDay from 0 to lastDate - 1
tell (curFmonth + oneDay * days) to set {wk, dy} to {its weekday as integer, its day}
if wk > 2 then
set folderName2 to text -2 thru -1 of ("0" & dy) & space & item wk of theWeekdays
try
tell application "Finder"
set folderName2 to make new folder at folderName1 as string as alias with properties {name:folderName2}
end tell
(* Create subfolder for each pub day in that month *)
end try
end if
end repeat
end tell
end try
set FMonth to FMonth + 1
set curFmonth to curFmonth + 1
(* Up the month by 1*)
end if
end repeat
I have I am unclear how to take the selected year and covert it back to a date so that the script will create the correct daily folders for that year. I know that what I have here is wrong but I am at an impasse till I can learn more about AS.
Model: MBP
AppleScript: 2.3
Browser: Safari 533.18.5
Operating System: Mac OS X (10.6)