Figured it out....
Figured it out....
- Subject: Figured it out....
- From: Steve <email@hidden>
- Date: Thu, 08 Nov 2001 15:53:47 -0800
Okay Folks,
I figured it out. Took a little while but I've now lost my AppleScript
virginity.
My lovely little script copies a folder over from a mounted Windoze drive to
a folder on my desktop and renames it with the current date. It does this
everyday when I shut my Mac down to go home. A famous person once said, "I
don9t need no stinkin IS person, I'll back up my own files".
Of course I stole bits of this from Apple but hey, a feller has to start out
somewhere...
Steve
tell application "Finder"
activate
select disk "MyLovelyHardDrive"
open selection
select folder "www" of disk "MyLovelyHardDrive"
open selection
select folder "customer_demo" of folder "www" of disk
"MyLovelyHardDrive"
copy selection to folder "Customer Backups"
end tell
set the date_slug to my format_date_using(the current date, "/", {"DD",
"MM", "YY"})
tell application "Finder"
activate
select folder "customer_demo" of folder "Customer Backups"
set name of selection to date_slug & "backup"
end tell
beep 2
display dialog "Backup complete. Go Home Now Please."
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