Re: Figured it out....
Re: Figured it out....
- Subject: Re: Figured it out....
- From: email@hidden
- Date: Fri, 9 Nov 2001 11:08:18 EST
Steve,
As you gain aptitude thru this list, you will discover that the 32k block of
code you spent all weekend creating can sometimes be better done in a few
short lines. As a example, here is my "date stamp" handler (highly adapted
from prior discussions on this list):
on frenchVanillaDottedDate()
set fullMonth to 2629728 -- 730.48 * 60 * 60
set halfMonth to fullMonth div 2 -- 1314864
set currDate to (current date)
copy currDate to janDate
set the month of janDate to January
set monthNum to (1 + (currDate - janDate + halfMonth) div fullMonth)
set mo to text -2 thru -1 of (("0" & monthNum) as string)
set da to text -2 thru -1 of ("0" & (day of currDate as string))
return ((year of currDate) & "." & mo & "." & da) as string
end frenchVanillaDottedDate
-- returns 2001.11.09 (today, anyway)
Hope you find it useful!
Jeff Baumann
email@hidden
www.linkedresources.com
In a message dated 11/8/01 8:35:53 PM, Steve Dampier wrote:
>
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