simple file copy problem

Not quite. I guess I have confused things a little so let me summarize:
I omitted one variable that you might need to know about:


set server_label to "aimaudit Backup"

“4D Server” is a local partition
“4D Data Mac” is a local partition
“aimaudit Backup” is a mounted share on a file server

So, your statement 1 is correct, although both volumes are local, but statement 2 is not. Everything is being duplicated to a mounted share (i.e. “aimaudit Backup”). The first 3 files do indeed get duplicated on the remote server. The intent is to make a copy of all the files and folders in the lists, in the single folder ‘new-folder’ on the mounted share.

Hopefully that clears up the confusion.

Ok, that clears things up a bit but I still don’t see why the troublesome files are being troublesome. Are you able to duplicate the files manually via drag and drop?

– Rob

Yes but a “descriptor type mismatch” seems more like some kind of Applescript usage issue then a permissions issue. I still think it has something to do with the fact that I am copying files from a subfolder, into a folder where that same subfolder does not exists. It strikes me that I have to use ‘duplicate’ rather then ‘copy’ and the command name implies a more strict match, to me.

If I can get the subfolder created on the destination share, perhaps that will answer that question.

As long as the file is being duplicated to a folder that already exists, it doesn’t matter where it is coming from. There’s no requirement that folder structures be identical unless it’s imposed by the code in the script.

Your mention of ‘copy’ vs. ‘duplicate’ confuses me. As far as I know, we have used only the ‘duplicate’ command. Have you been using ‘copy’ in the script?

– Rob

No, I was just distinguishing the difference between the more common ‘copy’ on Unix (cp actually) and Windows vs. ‘duplicate’ on OS X. It seems to me that ‘duplicate’ imples something more then a mere ‘copy’.

In any event, why is what should be a simple task, so difficult and what is the error message really trying to tell me?

It isn’t generally this difficult to create a script that duplicates files. The descriptor type mismatch error can be caused, for example, by…

tell application "Finder"
set foo to file "path:to:file"
duplicate file foo
end tell

When the script executes the duplicate command, it is being instructed to:

duplicate file file "path:to:file"

This will cause the error because foo isn’t being referred to correctly. The correct code is:

tell application "Finder"
set foo to "path:to:file"
duplicate file foo
end tell

Or

tell application "Finder"
set foo to file "path:to:file"
duplicate foo
end tell

– Rob

Isn’t generally this difficult? :shock: You must have forgotten what it is to be a beginner. :slight_smile: And I thought Unix was user hostile, expert friendly.

This is way too subtle for me. What is the difference between using ‘set’ to create the variable containing the path and filename and using ‘repeat’? I don’t see how what I did results in ‘file file’ shown in your first example.

I tried changing my script to use your suggestion but I still get the same error. I thought I was beginning to understand this stuff but now I realize I’m still clueless.

I remember what’s it’s like to be a beginner and that’s why I’m trying to exercise patience. :wink:

I suspect that part of the problem with troubleshooting the script is that you are cutting and pasting snippets of code here, instead of just pasting the entire script. If the entire script is too long to post, it might help if you create a test script that does nothing but duplicate the files. This will allow us to see the exact code that is failing and not just the part that you think is causing the problem.

I still don’t have a clue why the script works on some files and not others and I’m running out of guesses… err… suggestions. :wink:

– Rob

OK, I guess I was trying to avoid adding confusion by avoiding posting the whole mess and acheived the opposite. Sorry for trying your patience but I never imagined this would be so complicated (to me). Please know I really appreciate your efforts and the last thing I want is for you to get as exasperated as me. Here it is:


set server_location to "afp://user:password@10.0.0.1"
set server_label to "aimaudit Backup"
set source_files to {"4D Data Mac:aimauditDEV007.data", "4D Data Mac:aimauditDEV007.d2", "4D Data Mac:aimauditDEV007.d3", ¬
	"4D Server:Aim Operations:aimaudit.4db", "4D Server:Aim Operations:cert.pem", ¬
	"4D Server:Aim Operations:key.pem"}
set source_folders to {"4D Server:Aim Operations:MAC4DX", "4D Server:Aim Operations:WIN4DX", ¬
	"4D Server:Aim Operations:Web Root"}

set theDate to (current date)
set t to time of theDate
copy theDate to b
set b's month to January
-- Get an eight-digit number string in yyyymmdd format and extract what you need 
tell ((theDate's year) * 10000 + (b - 2500000 - theDate) div -2500000 * 100 + (theDate's day)) as string
	set folder_name to "aimauditBU" & text 1 thru 4 & text 5 thru 6 & text 7 thru 8
end tell
set hr to t div hours
set min to t mod hours div minutes
set hrmin to text 2 through 5 of ((10000 + hr * 100 + min) as string)
set folder_name to folder_name & "_" & hrmin
tell application "Finder"
	if (exists item (item 1 of source_files)) then
		try
			mount volume (server_location & "/" & server_label as string)
		on error error_message
			display dialog "Unable to connect to " & server_location & ":" & error_message
		end try
		set new_folder to (make new folder at folder server_label with properties {name:folder_name})
		make new folder at new_folder with properties {name:"Aim Operations"}
		tell application "4D Server"
			quit with delay 0
		end tell
		repeat with t_file in source_files
			set filename to t_file
			with timeout of 600 seconds
				duplicate file filename to new_folder
			end timeout
		end repeat
		repeat with t_folder in source_folders
			set foldername to t_folder
			with timeout of 600 seconds
				duplicate folder foldername to new_folder
			end timeout
		end repeat
		eject disk server_label
		else
		   display dialog "4D source files are not on this server."
	  end if
end tell

There are probably some things I need to remove/change in my varous attempts to implement suggestions.

Thank you. I have inspected the entire script and I’ve tested the part that creates the new folder and duplicates the files to it. It works fine here, but I haven’t introduced another volume into the mix. I cannot determine what is causing the problem. I still think it has something to do with the location of the original files since the failure occurs on the first file on the 4D Server volume. It could or could not be related to permissions or some other server related issue.

Have you tried removing file #4 from the list of files (source_files) to see if the script will proceed without it? Maybe it’s just an issue with one file.

I’m sorry that this has proven to be so difficult but I am really starting to think that the problem might not be strictly an AppleScript problem. Maybe, since you are a Unix person, you can work around it in the shell. AppleScript can issue shell commands directly via the ‘do shell script’ command (just in case you didn’t know).

do shell script “date”

I’m now grasping for anything that will get you going. :stuck_out_tongue:

– Rob (the one who has run out of answers)

Obviously I didn’t. :oops: What left field did you pull that one from??? You are dead on target. I have to examine that file more closely but at least I have something I can work on that I understand.

Other then that file, it works. Thanks and I owe you an adult beverage of your choice. Let me know if you are ever in the Atlanta area. :smiley:

I’m certainly glad to hear that you’ve made progress! Oh, for the record, I don’t think it was a field that I pulled that from but I’ll leave it at that. :wink:

I have no trips scheduled for Atlanta so feel free to give that adult beverage to someone who looks down on their luck and we’ll call it even. :slight_smile:

Cheers,
Rob