how to rename files?!?

I made this under System 8, it worked fine under OS9 but not now under OSX - whats wrong with this script:

tell application “Finder”
activate
select file “ADLTRU002.JPG” of folder “ADL” of folder “Macintosh HD:Opus0411:Pix”
set name of selection to “ADLTRU102.JPG”
select file “ADLTRU002_K.JPG” of folder “ADL” of folder “Macintosh HD:Opus0411:Pix”
set name of selection to “ADLTRU102_K.JPG”
if (exists folder “ADL” of folder “Macintosh HD:Opus0411:Pix”) = false then
make new folder at folder “Macintosh HD:Opus0411:Pix”
select folder “Neuer Ordner” of folder “Macintosh HD:Opus0411:Pix”
set name of selection to “ADL”
end if
select file “ADLTRU002_K.JPG” of folder “ADL” of folder “Macintosh HD:Opus0411:Pix”
move selection to folder “ADL” of folder “Macintosh HD:Opus0411:Pix”
select file “ADLTRU002.JPG” of folder “ADL” of folder “Macintosh HD:Opus0411:Pix”
move selection to folder “ADL” of folder “Macintosh HD:Opus0411:Pix”
end tell

It stops already at line 4 and gives the message:
Finder got an error: Can’t set name of selection to “ADLTRU102.JPG”.

My version is OS 10.2.8, Scripteditor D1-1.9

Thanx
Josh

From your error, it looks like it’s trying to name a selection, but the selection class doesn’t have a name property. It’s not figuring out that you really want to rename the file that’s in the selection.

You can try things like…

set name of (file “ADLTRU002.JPG” of folder “ADL” of folder “Macintosh HD:Opus0411:Pix”) to “ADLTRU102.JPG”

or

set name of first item of selection…

You can play around with different ways to do it, but make sure you’re addressing a file, not a selection instance.

hooray - this worked!!!
thx a LOT!

tell application “Finder”
activate
open folder “Macintosh HD:OpusX:PixCD”
select first file of folder “Macintosh HD:OpusX:PixCD”
copy selection
open file “OpusX.fp7” of folder “Macintosh HD:OpusX”
end tell

What I want to do is count the number of files in this folder. In the past I copied the name of the first and the last file to FileMaker. As the names are numbers between 01 and 99 I let FileMaker count the files.

But now this Script won’t work anymore:
Finder got an error: selection doesn’t understand the copy message.

I tried several other expressions:
select name of first file of folder “Macintosh HD:OpusX:PixCD”
copy selection

copy first file of folder "Macintosh HD:OpusX:PixCD"

copy name of first file of folder "Macintosh HD:OpusX:PixCD"

All of them don’t work! Arrrgh

What is the solution to this?

Would there be another possibility?

I tried:
set x to count files of folder “Macintosh HD:OpusX:PixCD”
copy x

Result:
Finder got an error: 11 doesn’t understand the copy message.

11 ist the correct number of files (hooray!) - but I can’t copy (and paste) it - WHY?

In the Library of Finder it says under
copy: (NOT AVAILABLE YET)
What the heck does that mean??
Can’t I use the copy command at all?

Here’s a simple script that counts all files and sub-folders of the targeted folder. Maybe it will be helpful.

set root_fol to (choose folder)

tell application "Finder"
	set files_ to count files of entire contents of root_fol
	set folders_ to count folders of entire contents of root_fol
end tell

display dialog ("Path: " & POSIX path of root_fol) & return & return & ¬
	"Files: " & files_ & return & "Sub-folders: " & folders_ & return & ¬
	"Total Item Count: " & (files_ + folders_) buttons ¬
	{"OK"} default button 1

– Rob

its a cool script - thanks!

But I need to give FileMaker the number of files.
Thats why I tried to COPY the number.
And WHY does the copy command don’t work?

Hi,

Copy is usually used in apps to place selected items onto the clipboard (text or images mostly). The Finder uses ‘duplicate’ to duplicate files and folders.

gl,