Move and rename file

I have a script that run is os 9 but not in OS X

here is the script

tell application “Finder”
activate

copy ((offset of (the month of (current date)) in ¬
	"jan feb mar apr may jun jul aug sep oct nov dec ") + 3) / 4 ¬
	as integer to mo
if mo < 10 then copy "0" & mo as string to mo
copy day of (current date) to da
if (day of (current date) < 10) then copy "0" & da as string to da
copy (year of (current date) as string) & "-" & mo & "-" & da to shortDate

select file "current timesheet.pdf" of folder "Timesheets" of folder "Shared" of folder "Users" of startup disk
set name of selection to shortDate
move selection to folder "Timesheets archive" of folder "Timesheets" of folder "Shared" of folder "Users" of startup disk
select file "Timesheet template(MC).pdf" of folder "timesheet template" of folder "Timesheets" of folder "Shared" of folder "Users" of startup disk
copy selection to folder "Timesheets" of folder "Shared" of folder "Users" of startup disk
select file "Timesheet template(MC).pdf" of folder "Timesheets" of folder "Shared" of folder "Users" of startup disk
set name of selection to "current timesheet.pdf"

end tell

and this is the event log

tell application “Finder”
activate
current date
date “Friday, January 28, 2005 12:11:21 PM”
offset of January in "jan feb mar apr may jun jul aug sep oct nov dec "
1
current date
date “Friday, January 28, 2005 12:11:21 PM”
current date
date “Friday, January 28, 2005 12:11:21 PM”
current date
date “Friday, January 28, 2005 12:11:21 PM”
select file “current timesheet.pdf” of folder “Timesheets” of folder “Shared” of folder “Users” of startup disk
document file “current timesheet.pdf” of folder “Timesheets” of folder “Shared” of folder “Users” of startup disk
set name of selection to “2005-01-28”
“Finder got an error: Can’t set name of selection to “2005-01-28”.”

any help would be great

As far as the Finder is concerned, ‘selection’ is a LIST of items. You can’t change the name of a list of items, only individual items.

Fortunately, the solution is simple - Don’t use ‘selection’ (it’s ugly, anyway, with apparently random windows opening, items selecting, etc… bleugh).

So, instead of:

select file "current timesheet.pdf" of folder "Timesheets" of folder "Shared" of folder "Users" of startup disk 
set name of selection to shortDate 

just:

set name of file "current timesheet.pdf" of folder "Timesheets" of folder "Shared" of folder "Users" of startup disk to shortDate

Or, even easier:

set name of file ":Users:Shared:Timesheets:current timesheet.pdf" to shortDate

Either way this works without opening the window, selecting the files, etc., etc., etc.

Similar techniques can (and should) be used for the move and duplicate commands (yes, you should ‘duplicate’ a file in the Finder, not ‘copy’ it since copy involves the clipboard).

nm