Inept Apple Shortcuts user needs help renaming, dating, moving files

This is something I did in Automator but which did not convert to Shortcuts or run as is on a modern Mac — and I cannot get my head around Shortcuts.
I save assorted utility and credit card bills to Downloads. I want to rename them, add the current date, and move them to respective folders. Bill A would get a Bill A name and go to the Bill A folder, etc.
They arrive in Downloads with various naming conventions but all types (gas, electricity, credit card) begin with different prefixes (text strings?). I want a separate Shortcut for each bill type. For the gas bill I would trigger the gas bill Shortcut , probably from the Services menu.
I want to avoid a clever omnibus Shortcut that would collect all the different bill types and distribute them to the relevant folders. Too complicated for me to troubleshoot or tweak.
But I can handle a “Run AppleScript with…” action. In Automator this one used to work:

on run {input, parameters}

tell application "Finder"
	move (file 1 of (path to downloads folder) whose name starts with "XX_X") to folder "Macintosh HD:Users:xxx:Bills:XX_X Bills"
end tell
return input

end run

I would be thrilled if someone can sort this! Cheers.

silvercoyote. It’s not clear to me if your request is for a shortcut that renames, dates, and moves files or to get the AppleScript in your post to work. If the latter is the case, the following worked on my computer. There’s no input that I can see, so the shortcut does not return any input.

Move Files.shortcut (21.7 KB)

If the former is the case, please include source and destination path examples, such as the following:

/Users/robert/Downloads/GAS Some Company.pdf # input path

/Users/robert/Bills/GAS/Some Company - 20251224.pdf # output path

FWIW, I went ahead and wrote a shortcut based on the above understanding. A few comments:

  • The user’s Home folder and the desired file name prefix must be set at the top of the shortcut.
  • The output file name has both date and time stamps to avoid having to deal with existing files in the destination folder.
  • If testing this shortcut, please be sure to have backups of the moved files.
  • The shortcut worked on my Tahoe computer without issue.
  • The following screenshot only shows a portion of the shortcut.

Move Files with Specified File Name Prefix.shortcut (24.3 KB)

Many thanks, peavine.
I’ve begun stumbling my way through this but it will take me some time. For a start, the term prefix may be more technical than I understood. Basically I mean just the first few letters of a file name. The script can’t find “statement.”, which is how one of the file names begins. It tells me no files with a filename prefix were found. So prefix must be the wrong term.
By the way I don’t need it to create a new folder or do repetitions. For me, “simple”.
Also, Christmas approaches and you may have better things to do — much as I appreciate your help!

silvercoyote. Sorry that didn’t work.

I’m still at a bit of a loss as to what the shortcut is supposed to do. Perhaps another forum member will better understand and be able to help.

silvercoyote. I found an error in my earlier shortcut, and I rewrote it for simplicity and to work on the first letters of the file name. I do not use the term “prefix” and instead use the term “specified letters”. To test this shortcut:

  1. Set the source and destination folders in the first section of the shortcut.
  2. Set the text action in the first section of the shortcut to the desired letters (the current value is ABC).
  3. Place some files in the source folder that begin with the specified letters and run the shortcut.

Move Files.shortcut (24.1 KB)

I’ve been working to relearn forgotten shell-script skills, and I rewrote the above shortcut for practice. It probably needs some error checking.

Move Files.shortcut (21.9 KB)

1 Like

That’s fantastic, peavine! It works, complete with added date. Out of curiosity, what shell script language do you use? I’m familiar enough with AppleScript to realize it’s not that.
Regards, and many thanks.

silvercoyote. I normally use the zsh shell, which is the default in recent versions of macos. However, my script worked correctly with the bash but not the zsh shell. I need to research this.

FWIW, I edited the above shortcut to include basic error reporting.

Move Files with Error Dialog.shortcut (22.5 KB)

1 Like

That’s a useful tweak — and it works! Thanks again, peavine.