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.