Error moving or renaming file

OK, this is probably going to be pretty stupid.

I am trying to rotate a log file by renaming it. The file lives in ~/Library/Logs. My script will create the file and write to it, but if I add a routine to rename the file after a certain size I get an error:

 [b]AppleScript Error[/b]
 Finder got an error: Can't set name of file
 "iTunesSync.log" of folder "Users:trinkel:Library:Logs"
 to "iTunesSync.log.1".

Here is the main part of the script:

global logName
set logName to "iTunesSync.log"
global logArch
global logDir
global logFile
set theUser to (do shell script "whoami")
set logDir to "Users:" & theUser & ":Library:Logs"
set logFile to logDir & ":" & logName
set logArch to logName & ".1"
set logSize to 1 * 1024 -- In KB
if (size of (info for file logFile)) > logSize then
	tell application "Finder"
		set the name of file logName of folder logDir to logArch -- Problem here
	end tell
end if
set the openFile to open for access file logFile with write permission
write "Run: " & (current date) & [return] to the openFile starting at eof
close access the openFile

For both the original file and the new name I’ve tried the variable as "filename of folder . . . " and just the filename. So far all the variations have given me similar errors. I’ve also tried moving the file rather than setting the name and do shell mv, All with similar results.

If I display dialog on the variables, they seem to be OK, and again, I can create and write to the file.

I know I’m at least in the ball park 'cause I got the set name syntax straight out of several posts. This has got to be some sort of freaky data type thing and I’m just not getting it.

Any ideas?


Operating System: Mac OS X (10.4)


I don’t know if this will help or not, but this is a snippet of code from a script I wrote. This renames a file that has been created. Maybe you can adapt this for your purposes.

select file "untitled archive.sit" of folder destPath -- select your file here
				set thisArchive to selection as alias -- set a variable to point to your file
				set name of thisArchive to completeFile -- rename the file 

I don’t know why I set it up this way but it works alright.


Nope, that didn’t do it either. This time I got the error on the “select”. Said it could not get the file. Honest to God, it’s there.

I think it must me something more fundamental.


Looking closer at your code, do you have the complete path to the file listed:

logDir is set to

I think there should be a hard drive name before the Users.



Thanks! That seemed to do it. I knew it had to be something silly that I was forgetting :stuck_out_tongue:

Kinda odd that I didn’t need it for the “open for access” routine.

ooh ooh! I just noticed the rename is inside a finder tell and the open for access isn’t. Maybe that’s the difference.

Ah well. Thanks again


You might be able to simplify that a little bit:

property logFile : file specification ((path to library folder from user domain as Unicode text) & "Logs:iTunesSync.log")
property logSize : 1 * 1024
property newName : "iTunesSync.1"

if (size of (info for file logFile)) > logSize then
		tell application "Finder" to set name of logFile to newName
	on error errorMsg number errorNum
		display dialog "Error (" & errorNum & "):" & return & return & errorMsg buttons "Cancel" default button 1 with icon caution
	end try
end if

	set openFileRef to open for access logFile with write permission
	write ("Run: " & (current date) & return) to openFileRef starting at eof
	close access openFileRef
on error
		close access openFileRef
	end try
end try

Thanks Bruce,

I’ll give that a shot. Looks a lot more professional. I’m also going to have to either delete the existing .1 file or replace. Simply adding “with replace” didn’t seem to cut it. I’ll futz with that tonight.

Again, thanks for your help.