What happened to "Copy" in Tiger?

I have a script that ran fine in Panther that now is completely broken. When I look at the fider dictionary, I see

copy‚v : (NOT AVAILABLE YET) Copy the selected items to the clipboard (the Finder must be the front application)
copy

Does this mean that the command does not work in Tiger?

Model: iMac G5 2ghz
AppleScript: 1.10
Browser: Safari 412.5
Operating System: Mac OS X (10.4)

It’s true that Finder’s copy command isn’t available in Tiger - although I was under the impression that, in OS X at least, it was ever thus. (IIRC, the copy command in Finder was once a synonym for ‘duplicate’, although that was dropped some back - presumably to avoid confusion.)

You could use UI scripting to get Finder to copy, but it’s curious that your script worked in Panther. Are you saying that Finder copied successfully there - and what error message do you now get in Tiger? (Perhaps you could post your script, to see if someone can help you identify what the specific problem is…)

Use this instead:

on copy_file(item_path, the_dest)
	try
		set the_item to quoted form of POSIX path of item_path
		set the_dest to quoted form of POSIX path of the_dest
		do shell script "cp  " & the_item & " " & the_dest
	on error errorMessage
		display dialog errorMessage
	end try
end copy_file

It’s confusing enough having a completely different command with that name in the AppleScript language! :wink:

On my OS 8.6 machine, the Finder’s ‘copy’ command appears to put just the names of specified files or folders onto the clipboard. I don’t know why it bothers, since trying to retrieve them merely causes errors. I can confirm that this doesn’t work at all in any version of OS X.

In the form ‘copy [item] to [destination]’, it can indeed be used instead of ‘duplicate [item] to [destination]’. This is still possible with Tiger’s Finder, but it’s been considered “wrong” for as long as I can remember.

I am not sure what the intent of the original question is, but the terminal commands pbcopy and pbpaste copy and paste from the clipboard.

I suppose you could get something into the clipboard with:

set text_ to "Here I come to save the day!"
set the_script to "echo " & text_ & " | pbcopy"
do shell script the_script

Andy

Thanks, Nigel - my recollection was clearly coloured by wishful thinking! :wink:

In that case, for anyone unfamiliar with this, it might be worth going through it in slightly more detail. So here are some examples of using Finder’s duplicate and/or copy commands…

The example statements below use a combination of the following variables and (dummy) values:

(We could also copy/duplicate a folder but, for simplicity, let’s just stick to a file.)

These single-line statements all duplicate as expected here (Mac OS 10.4.2):

Now, using the copy command, these work in a similar way:

However, these don’t:

Instead, these last two statements are interpreted as AppleScript copy commands - so the value of the variables ‘folderPath’ and ‘folderAlias’ are merely changed to that of ‘filePath’ (“disk:path:to:a:file”) and ‘fileAlias’ (alias “disk:path:to:a:file”), respectively. (Of course, this may or may not be what the scripter intends - but, since nothing actually takes place in Finder, there’s not much point in putting the commands in a Finder tell statement anyway.)

Any confusion is likely to increase when Finder’s other copy command becomes available. So the moral is generally: If you mean “duplicate”, then say “duplicate”.

And if you mean “copy” (the one that isn’t available yet), then (until it is) you could always do something like:

tell application "Finder" to activate
tell application "System Events" to keystroke "c" using command down (* copy current selection *)

I hope this hasn’t added to the confusion… :slight_smile:

For the sake of precision, I suppose I should clarify that when I say “for as long as I can remember”, I really mean “for as long as I’ve been a Mac User and taking part in AppleScript forums” ” a trifle under eight years. I can of course remember a lot further back than that. :wink:

Thanks for your in-depth exploration, kai. I’ve always (that is, since I’ve been a Mac user etc…) been slightly unnerved that the misuse of ‘copy’ in the Finder actually works. Whereas ‘duplicate’ and its optional ‘to’ parameter compile as application keywords (as you’d expect), ‘copy’ and ‘to’ in this context compile as language keywords. And yet they successfully perform a Finder action:

tell application "Finder"
	set fred to file "Geifr yn bla mewn pentref.rtf" of desktop
	
	-- Proper Finder usages which compile with application keywords.
	duplicate fred to startup disk
	copy fred -- currently not working
	
	-- Improper useage, compiles with language keywords, but works! 
	copy fred to startup disk
end tell

Weird…

Wow! And I think I’m doing alright if I can remember what I had for lunch yesterday. :rolleyes:

It does kinda chip away at one’s confidence somewhat. It’s almost as if the displayed format and the compiled code are starting to go in different directions… :o

Most definitely. Almost on a par with some of your filenames, Nigel. :stuck_out_tongue: