set file name to weekday

Trying to figure out what's wrong with this script. I think it has to do with the way the path is written?


tell application "Finder"

set name of file "/Users/gmpro/Desktop/xxx.png" to (weekday of (current date))

end tell



Thanks

iMac Line (2012 and Later)

Posted on Jun 28, 2021 8:58 PM

Reply
2 replies

Jun 29, 2021 12:48 PM in response to mrokloricred37

This is primarily an issue of path style. You're passing in a POSIX path whereas the Finder deals with either Mac-style paths (colon-delimited) or its own file class.

Despite it being many years, the Finder still can't automatically coerce between them, so you have to do it:


tell application "Finder"
	set f to POSIX file "/Users/gmpro/Desktop/xxx.html"
	set name of file f to (weekday of (current date)) as text
end tell


(note that I've added 'as text' to the target filename - that's because 'weekday' is actually an enumeration and will result in something like 'mon', 'tue', etc. whereas coercing it to text gives you the full day name ('Monday', 'Tuesday', etc.)


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

set file name to weekday

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.