FileManagerLib and rename object command

I’m trying to write an AppleScript to handle some file conversions I need, but I was running into trouble, since I need to be able to continue to refer to the files after the renaming. I ran across this site and the FileManagerLib, which seems like it should do the trick, but I’m errors when I don’t think I should be. So I’ve constructed a minimal example of the problem.

use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use script "FileManagerLib" version "2.3.5"
use scripting additions

tell application "Finder"
	set theFile to selection
end tell

rename object theFile to name "bob"

Here’s the sequence of events I get:

tell application "Finder"
	get selection
	get document file "Figure 1@1" of folder " Section 1" of folder " Polyhedra course 2001" of folder "Lexar" of disk "Brankos Brain"
Result:
error "Can’t make «class docf» \"Figure 1@1\" of «class cfol» \" Section 1\" of «class cfol» \" Polyhedra course 2001\" of «class cfol» \"Lexar\" of «class cdis» \"Brankos Brain\" of application \"Finder\" into the expected type." number -1700 from «class docf» "Figure 1@1" of «class cfol» " Section 1" of «class cfol» " Polyhedra course 2001" of «class cfol» "Lexar" of «class cdis» "Brankos Brain"

Needless to say, it fails to rename the file.

Also… I couldn’t figure out how to get the rename object command to return the posix path… when I typed in what looked like it obeyed the appropriate formatting, I didn’t get anything useful out. An example of what that looks like would be SUPER helpful.

The problem is that theFile is a Finder reference, which only the Finder can deal with. You need to convert it to something FinderLib can work with, like an alias or path – for example:

tell application "Finder"
	set theFile to selection as alias
end tell

That was actually super helpful. It does suggest that my code snippet didn’t capture the full extent of my problems. However, I may now have enough to work with to fix it (it was working unreliably in my longer AppleScript).

Just for fun, in case anyone else is confused on the question, here’s a slightly longer code example that makes use of the return path option.

use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use script "FileManagerLib" version "2.3.5"
use scripting additions

tell application "Finder"
	set theFile to selection as alias
end tell

set myVariable to rename object theFile to name "bob" with return path
log myVariable --> (*/Volumes/Brankos Brain/bob*)

set myFile to POSIX file myVariable
log myFile --> (*file Brankos Brain:bob*)