Okay I need to rename folders with the day’s date. Basically what I have is the program copies a folder from one part of the hard drive to another as a backup. The problem is I want to rename the folder to the date of that day. I can’t have any scripting additions because of the way the computers are loaded. Here is what I have come up with (which doesn’t work:)
tell application "Finder"
activate
set thedate to (current date)
set thedate to (characters 1 through 30 of thedate)
select folder "New Folder" of startup disk
set name of folder to thedate
end tell
My (stupid) thinking was to get just characters 1-30 to avoid picking up the “:” since you can’t put that into the name of file. All I really want is to have the folder’s renamed to something like “01292002” or ANYTHING that is close to that. It could even be 012902 for 29th of jan 2002. I have searched the archives for hours and have been unable to find something about this. I would settle for “Tuesday, January 29, 2002” if need be.
The following worked for me - – Handler copied from BSCS.com29.txt of Applescript GuideBooks
tell application "Finder"
set the members_list to {"AirMiles", "The Bay", "Computer", "LloydsTSB", "LOADS", "LOC", ¬
"TelPay", "Test", "U.K. £", "VAC", "VISA"}
set the dialog_result to ¬
choose from list members_list with prompt ¬
"Where should the snapshot to go - the date will be added to the file name."
if the dialog_result is false then
return "user cancelled"
else
set this_member to the first item of the dialog_result
end if
copy the this_member as list to {the snapshot}
activate
open selection
select file "Picture 1" of startup disk
set name of selection to the snapshot
move file snapshot of startup disk to folder snapshot of folder ¬
"Snapshots" of folder "Utilities" of folder ¬
"Applications" of startup disk
set the date_slug to my format_date_using(the current date, ".", ¬
{"YY", "MM", "DD"})
select file snapshot of folder snapshot of folder ¬
"Snapshots" of folder "Utilities" of folder ¬
"Applications" of startup disk
set name of selection to snapshot & " " & date_slug
end tell
-- Handler copied from BSCS.com29.txt of Applescript GuideBooks
on format_date_using(this_date_record, delimiter_string, format_list)
-- get the numeric day
set numeric_day to the day of this_date_record
-- get the month
set month_name to the month of this_date_record
-- convert month to number
set the list_of_months to {January, February, March, April ¬
, May, June, July, August, September, October, November, December}
repeat with i from 1 to 12
if item i of the list_of_months is the month_name then
set the numeric_month to i
exit repeat
end if
end repeat
-- get the numeric year as text
set numeric_year to the year of this_date_record as string
set the formatted_date to ""
-- count the number of items in the list
set the item_count to the count of the format_list
-- parse the format list
repeat with i from 1 to the item_count
set this_item to item i of the format_list
if this_item is "D" then
set the formatted_date to ¬
the formatted_date & numeric_day as string
else if this_item is "DD" then
if the numeric_day is less than 10 then ¬
set numeric_day to ¬
("0" & (the numeric_day as string))
set the formatted_date to ¬
the formatted_date & numeric_day as string
else if this_item is "M" then
set the formatted_date to ¬
the formatted_date & numeric_month as string
else if this_item is "MM" then
if the numeric_month is less than 10 then ¬
set numeric_month to ¬
("0" & (the numeric_month as string))
set the formatted_date to ¬
the formatted_date & numeric_month as string
else if this_item is "YY" then
set the formatted_date to ¬
the formatted_date & ¬
((characters 3 thru 4 of numeric_year) as string)
else if this_item is "YYYY" then
set the formatted_date to ¬
the formatted_date & numeric_year
end if
if i is not the item_count then
-- add delimiter
set the formatted_date to ¬
the formatted_date & delimiter_string as string
end if
end repeat
return the formatted_date
end format_date_using