Change day daily

I am looking to change the name of a file daily. The format would be Weekday DATE.png eg Monday DATE.png. Tried using automator which works once, but I need to be able to regenerate the DATA.png file to run it again and can't figure how to do this in automator or AppleScript.


Succinctly, I am looking for a script which will title a DATA .png file with the day of the week as its prefix whenever the script is run.

It would also work if I had any file with the entire title as the current day of the week eg Monday


iMac Line (2012 and Later)

Posted on Jul 8, 2020 1:31 PM

Reply
5 replies

Jul 8, 2020 3:54 PM in response to mrokloricred37

I think you need to better define your workflow. It's clear you know what you want, but it's how to translate that into Automator (or something else).


Let's start with the fact you use the 'Get Specified Finder Items'. That, by definition, will look for a specific file on disk. It has no way of knowing that the file has been moved or renamed. How could it?

Instead, consider using the 'Ask for Finder Items' action. This puts up the standard Open File dialog where you can choose which file to select. Yes, it's a manual step, but it removes any ambiguity about which file to change.


Alternatively, did you consider my alternative ideas on how to invoke the script? A droplet also eliminates ambiguity because you drop the specific file(s) you want to rename onto the script.

Another alternative is to insert the 'Copy Finder Items' action after the 'Get Specified Finder Items', then rename the resulting file. Now you have the original DATE.png as well as the Monday DATE.png file, so subsequent iterations of the script will still have a base file to work with.


Again, it's all a matter of defining the rules of engagement in terms the OS can understand.

Jul 8, 2020 1:42 PM in response to mrokloricred37

It's not entirely clear what you're asking for, since your existing workflow seems to do what you're asking for.


Is it the scheduling part you're looking for? There is no action scheduling in Automator - so it has no idea when it might need to be run again.


There are other ways of approaching this, though, depending on your eventual goal.


You can setup watch folders using Folder Actions that will fire off whenever a new file is dropped in a folder - works if you have a specific folder where new 'DATA.png' files are created.

You could setup a polling script where it checks periodically to see if there are any new files around.

You could create a droplet that reacts to files dropped on it (drop DATA.png onto the script and have it renamed), although this does include a manual component.


But maybe I've misunderstood the ask. Feel free to clarify.

Jul 8, 2020 3:03 PM in response to Camelot

Hi,

I want any file (cou.ld be .pdf,.jpg )or whatever to have its title be the day of the week: Monday, Tuesday, etc.. The above automator script eliminates the DATE.png after it runs as it puts the day of the week before DATE and changes the name of DATE.png to Wednesday DATE.png. So the next time it runs it can't find DATE.png. Since it is now Wednesday DATE.png and the script won't change the day, if it is Thursday unless Wednesday is physically erased before the script runs.


Jul 9, 2020 10:38 AM in response to mrokloricred37

OK, that helps.


But there still remains some gaps - specifically about identifying the file to change.


For example, you say 'any file... on the desktop'. Do you really mean any file? Most people I know have a smattering of files on their desktop. Maybe you're more organized than most, and that's OK. Just making sure.


Secondly, you started out describing a single file, but now it sounds like you want to be able to handle multiple files. Is that so?


Also, just for clarification: 'If I ran the script on Thursday, the filename would change to Thursday'

Does this mean that if you have a file 'DATA.jpg' and you run the script on Wednesday, it renames to 'Wednesday DATA.jpg'. If you then run the script again on Thursday, it changes to 'Thursday DATA.jpg'. That's a whole lot different from 'prefixing the current day name' which would ordinarily result in 'Thursday Wednesday DATA.jpg'.

You see, it's these kinds of details/corner cases that make the difference between a useful, working script and a hack. If you want to remove the existing day name then you have to do a whole lot more work. Not that it's impossible, but that wasn't clear in the original ask. It's also way past Automator's direct ability since it has very little conditional execution.


Fortunately, it is possible to do via AppleScript, and you can put the script in a 'Run AppleScript' action to get the desired result.


Here's a rough, barely tested, model in AppleScript:


-- list of day names to filter out
set day_names to {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}
-- get the current day name
set current_day to weekday of (get current date)

tell application "Finder"
	-- get the files on the desktop
	set files_to_rename to (get every file of (path to desktop))
	-- loop through them
	repeat with each_file in files_to_rename
		-- extract the current file's name
		set the_filename to name of each_file
		-- check if it begins with a day name
		if word 1 of the_filename is in day_names then
			-- if it does, strip off the leading word
			set base_name to characters (2 + (length of word 1 of the_filename)) through end of the_filename as text
		else
			-- otherwise go with the whole thing
			set base_name to the_filename
		end if
		
		-- now construct the new file name by combining the current day and filename
		set new_name to current_day & space & base_name as text
		-- and rename the file
		set name of each_file to new_name
	end repeat
end tell


Paste this into a 'Run AppleScript' action, save your workflow as an application, then any time you run it, it will rename all the files on your desktop to include the current day name, stripping any leading day names on existing files.

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.

Change day daily

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