Pointing at the documents folder

Hello,

I’m totally new to Applescript, and I’m trying to make some proof-of-concept scripts. Right now I’m renaming a file. Doing it on the desktop is easy,


tell application "Finder"
	set the name of file "test.txt" to "test2.txt"
end tell

I run into trouble when trying to do it for another folder, though. I want the file test.txt stored in Documents/Test, and I’m guessing I can do this with

(path to documents folder)

(and maybe POSIX?), but I tend to get error-messages whatever I try. Anyone who can help me on this? I don’t want the username to be hard-coded into the script, as it wouldn’t run on other users. That’s why I’m guessing “path to documents folder” is a good start.

Thanks :slight_smile:

Hi,

welcome to MacScripter :slight_smile:

path to documents folder is the right way, but the class is alias and you need a string path to concatenate it with your filename

set p to path to documents folder as Unicode text
tell application "Finder"
	set the name of file (p & "test.txt") to "test2.txt"
end tell