Error moving a file

set source_folder to “MacintoshHD:”
set target_folder to “MacintoshHD:users:jamcrae:Desktop:watchedfolder:In:”
tell application “Finder” to move (file “earth.ps” of folder source_folder) to folder target_folder

I’m getting the message
“Finder got an error: Can’t get file “earth.pdf” of folder “MacintoshHD:”.”

The file is definitely there. I’ve tried referring to it as file, item, document, document file and I get the same message each time. Please, what am i missing??

JA

I can’t get this script to fail under any circumstance other than when the file doesn’t exist (or it’s path is incorrect).

For example, you’re sure your disk name is “MacintoshHD” and not “Macintosh HD”?

I was fully prepared to sink into the floor with embarassment, but no… it still won’t work.
I cut and pasted the name of the drive to be sure and I get the same error message.

Should I try writing a quick “Choose a file” script so I can test the path? Could I be missing something from the computer’s scripatbility? I’m in Panther, so I would have figured all the features would be working…

JA

jageo,

In your first post, you refer to two different files - earth.ps and earth.pdf. Is this at the heart of your problem?

– Rob

OK… i can choose the file, and see its path as an alias. It is correct

What could be reasons the Finder can not get a file?
JA

Sorry Rob, no, that’s just my bad typing. :oops: I’ve tried with a couple different files to be sure i’m not making that mistake.
Thanks anyway…
JA

Ok I tried this to preserve my sanity:

tell application “Finder”
if exists (file “Macintosh HD:earth.pdf”) then
beep 2
end if
end tell

And it comes back “true”, the file is there… why can’t i get it?
JA

(note: i did benefit from Camelot’s correction, but it still isn’t the root of the problem…)

Could it be because it’s outside of your user domain?

– Rob

I tried this… figuring it should be in my user domain. There is only one user, and it is administrator.

set source_folder to “Macintosh HD:Users:jamcrae:Desktop:watched folder:In:”
set target_folder to “Macintosh HD:users:jamcrae:Desktop:watchedfolder:Out:”
tell application “Finder”
if exists (file “earth.pdf” of folder source_folder) then
beep 2
tell application “Finder” to move (file “earth.pdf” of folder source_folder) to folder target_folder
end if
end tell

result: I get the 2 beeps, but the error message “Finder got an error: Can’t get file “earth.pdf” of folder “Macintosh HD:Users:jamcrae:Desktop:watched folder:In:”.”

Any test that you can think of for me to try?

Also… (still testing) I can get the finder to delete the file
I can get the finder to duplicate the file

Can’t make it duplicate to the target folder yet I haven’t got the right syntax.

This line:
tell application “Finder” to duplicate (file “earth.pdf” of folder source_folder) to folder target_folder

returns this error
“Finder got an error: Can’t set folder “Macintosh HD:users:jamcrae:Desktop:watchedfolder:IN:” to file “earth.pdf” of folder “Macintosh HD:”.”

JA

Does this work?

set file_ to (choose file with prompt "Choose the file to move.")
set destination_ to (choose folder with prompt "Choose the destination for the previously selected file.")
try
	tell application "Finder" to move file_ to destination_
end try
{file_ as Unicode text, destination_ as Unicode text}

It might also be helpful if you share the contents of the result window after running the script.

– Rob

OK, given that the file does exist, have you checked that you actually have permissions to move it - either the original file, or either of the source or destination directories?

You need to have write permission on the directories in order to delete or add files to the directory.

Also, is the file locked?

Can you move the file in the Finder?

Rob’s latest code works. Many thanks. The difference appears to be the line about the Unicode text? Can someone direct me to information about the Unicode text line so I can read up on it?

Now I just need to adapt so i don’t have to choose the file, and hard code the destination folder. (When finished the script will print a PS file from Quark XPress to the root directory with a unique file name, wait for the file to exist, then move it to a Distiller watched folder)

I’ll upload the code as i make things work in case anyone does searches for a similar problem.
JA[/i]

The line in the script that includes the reference to Unicode text should have no impact on the performance of the script. If you remove it, the script should still perform exactly as it did before. It was added simply to provide feedback during our troubleshooting session here. You can use the result of the following script to obtain the correct paths (run the script and check the result window/pane. They can then be pasted into your script so that the dialogs can be eliminated.

set file_ to (choose file with prompt "Choose the file to move.")
set destination_ to (choose folder with prompt "Choose the destination for the previously selected file.")
{file_ as Unicode text, destination_ as Unicode text}

Do any of the paths involved in your script include non-ASCII characters?

– Rob

This is the result returned. For the file to be moved it appears to be telling me the path after it gets moved, as I am actually chosing it from the root level of Macintosh HD.


{"Macintosh HD:Users:jamcrae:Desktop:watched folder:In:earth.pdf", "Macintosh HD:Users:jamcrae:Desktop:watched folder:In:"}

when i watch the event log instead, i can see one difference from yesterday is that it says “move alias” instead of “move file”


tell current application
	choose file with prompt "Choose the file to move."
		[color=darkblue]alias "Macintosh HD:earth.pdf"[/color]
	choose folder with prompt "Choose the destination for the previously selected file."
		[color=darkblue]alias "Macintosh HD:Users:jamcrae:Desktop:watched folder:In:"[/color]
end tell
tell application "Finder"
	move alias "Macintosh HD:earth.pdf" to alias "Macintosh HD:Users:jamcrae:Desktop:watched folder:In:"
		[color=darkblue]document file "earth.pdf" of folder "In" of folder "watched folder" of folder "Desktop" of folder "jamcrae" of folder "Users" of startup disk[/color]
end tell

Based on your feedback, this should work.

tell application "Finder" 
   move alias "Macintosh HD:earth.pdf" to alias "Macintosh HD:Users:jamcrae:Desktop:watched folder:In:" 
end tell

The reference to the file in its new location is expected behavior. This allows further processing, such as a name change or manipulation by an application, after it has been moved. It would look something like this:

tell application "Finder" 
  set moved_ to (move alias "Macintosh HD:earth.pdf" to alias "Macintosh HD:Users:jamcrae:Desktop:watched folder:In:")
  set name of moved_ to "Planet.pdf"
end tell

– Rob

Below is the whole deal, working from start to finish. It makes a PS file of a Quark 6.0 spread, saves with the name of the file and the settings required by our service provider. Saves to the root level, waits for the file to be finished, then moves it to the In folder where Acrobat Distiller takes over from there.

You’re saying Rob that I can drop the last line about Unicode text, correct? That is was just to show text in the result window?
Many thanks for walking me through this. I think the hardest part I have understanding is when something is refered to as an alias. Not always sure of the proper purpose and the proper syntax

JA


set theHD to (path to startup disk as string)
set savePath to theHD
tell application "QuarkXPress"
	if (exists document 1) is false then return beep 2
	tell document 1
		try
			set docName to the name
		on error --will error if document is not saved
			set docName to "UnsavedFile"
		end try
		set properties of print setup to {orientation:landscape, reduce or enlarge:100, registration marks:centered, registration marks offset:6, halftone screen:"100", resolution:"1270", print spreads:true, data format:binary data, paper size:"custom", paper width:"17.5", printer type:"Generic Imagesetter", separation:false, tiling:off, print colors:grayscale}
		set fileName to savePath & docName & ".ps"
		print PostScript file fileName
	end tell
end tell

set goAhead to 0
repeat until goAhead = 1
	tell application "Finder"
		if file fileName exists then
			set goAhead to 1
		end if
	end tell
end repeat

set file_ to fileName
set destination_ to "Macintosh HD:Users:jamcrae:Desktop:watched folder:In:"

try
	tell application "Finder" to move file_ to destination_
end try
{file_ as Unicode text, destination_ as Unicode text}

Correct.

I suggest that in most cases, you should first try to use an alias reference. If you plan to do much scripting, I urge you to get a good book on AppleScript. I haven’t obtained any of the latest releases so I hesitate to recommend one. Otherwise, I’ll leave the explanation to someone who is articulate enough to talk about aliases in a way that makes sense. :wink:

Applescript for Quark XPRess by Shirley W. Hopkins
Applescript Handbook - Danny Goodman
The Tao of Applescript - Derrick Schneider

The last two are a little old as I used them years ago to write some original scripts. I have to return to scripting to update for system 10 and Quark 6. Many have changed in such a subtle way that it is difficult to find in a book just what the fix should be.
Although, i admit, I really should get something newer.

JA