Finding the right syntax for renaming files with FileManagerLib

Hi all,

I am trying to figure out what the correct syntax for renaming a file using Shane’s FileMangerLib.

Looking at the readme, it looks like it should be as simple as

set rename object theItem to (("hello") as string)

But that is probably a really gross line of code on my part.

Like I said I have looked at the readme, but there are no examples in that of using the rename command, in fact I can’t seem to find a single example online. So I have come here to seek guidance.

For reference, here is the entire script:

use scripting additions
use theLib : script "FileManagerLib" version "2.2.1"
set folderPath to POSIX path of (choose folder with prompt "Choose a folder:")
set theFolder to POSIX file folderPath as alias
set theContents to objects of theFolder
repeat with i from 1 to (count of items of theContents)
	set theItem to item i of theContents
	set aliasItem to (POSIX file theItem) as alias
	set rename object aliasItem to (("hello" & i) as string)
end repeat

That gives me a stack overflow error when I try to run it from both Script Debugger 7 and Script Editor 2.10. I am running on 10.13.

Looking at examples for some of the other commands in FileManagerLib I realize that what I am trying to do is probably too simplistic, and the right way probably involves a bit more code.

Model: 2018 MBP 15"
Browser: Safari 605.1.15
Operating System: macOS 10.13

The second parameter is named to name, so:

rename object theItem to name "hello"

Your full script can be simplified a bit:

use scripting additions
use theLib : script "FileManagerLib" version "2.2.1"

set theFolder to (choose folder with prompt "Choose a folder you don't mind mangling:")
set theContents to objects of theFolder
repeat with i from 1 to count of theContents
	rename object (item i of theContents) to name ("hello" & i)
end repeat

Thanks Shane. Sometimes it is the simplest things that we miss! Should have tried “name”…

It really does pay to check the parameter names in the dictionary. For any app/library, they’re something that’s easy to get wrong.

Does FileManagerLib have a dictionary? I tried to open it in SD and unlike some of your other libraries it just opened the library, it did not first ask me if I wanted to open the dictionary or the script.

Yes it has.
You may reach it thru : File > Open Dictionary > Applications then navigate to the Script Libraries folder storing it.

Yvan KOENIG running High Sierra 10.13.6 in French (VALLAURIS, France) vendredi 14 juin 2019 20:19:25

That’s odd – I can’t reproduce that. If it happens again, please drop me an email.

I was able to open the Dictionary using Yvan’s advice.