Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Create a Folder with the mm/yy at the end of it using Automator

Hello,

I would like to adjust this to create that first base folder to add a space, the current month and year to the end of the folder name to be shown like this for example:

123456 01/23


See attached for what it looks like currently.

Posted on Jan 24, 2023 11:43 AM

Reply
Question marked as Best reply

Posted on Jan 25, 2023 12:54 PM

I would suggest learning the basics of the shell. Either bash or now the Apple-preferred zsh. See the other topics I’ve previously mentioned. I’ve included some info and links on scripting. i’ve also included how to work with dates in the shell.


Launch Terminal.app and practice with the mkdir command. The core of this question is that pair of mkdir commands.


Automator passes two arguments into that shell command, which are represented as $1 and $2 in the mkdir commands. When the mkdir command is invoked, $1 is replaced with the first argument, and $2 with the second.


The first of the two mkdir commands creates the top directory. The second creates the second directory within.


Whoever coded that either didn’t know about or didn’t think about using mkdir -p, which creates intermediate directories when and as needed. Using mkdir -p, those two commands could become one. This one:


mkdir -p "$1$/$2/info"


Note that vertical double quotes are shown here and are necessary syntax, and not angle quotes that the forum software prefers to insert.


To make that mkdir command do what you want (if I understand your request here correctly), use this command:


mkdir -p "$1 $2/info"


That command creates a directory based on whatever is in $1 and a space and whatever is in $2, and a with a subdirectory named info.


This assumes you are passing the date into the mkdir command from your Automator script as the second argument.


If you want that date stuff to happen automatically, using one argument and the current date:


mkdir -p "$1 $(date -j +"%Y%m")/info"


That generates a four digit year and a two digit month in the path. Which will sort in the expected order in Finder and elsewhere, where %m%Y won’t.


A shell script can prompt users for input using an osascript call, as needed. Automator and Shortcuts are good for some stuff, but can get in the way for other tasks. This is one of those latter areas.


PS: Here are some of the zsh shell-scripting threads mentioned earlier:

... short cut date as file name - Apple Community

... How can I append wildcards to a variable? - Apple Community

3 replies
Question marked as Best reply

Jan 25, 2023 12:54 PM in response to Neecerp3

I would suggest learning the basics of the shell. Either bash or now the Apple-preferred zsh. See the other topics I’ve previously mentioned. I’ve included some info and links on scripting. i’ve also included how to work with dates in the shell.


Launch Terminal.app and practice with the mkdir command. The core of this question is that pair of mkdir commands.


Automator passes two arguments into that shell command, which are represented as $1 and $2 in the mkdir commands. When the mkdir command is invoked, $1 is replaced with the first argument, and $2 with the second.


The first of the two mkdir commands creates the top directory. The second creates the second directory within.


Whoever coded that either didn’t know about or didn’t think about using mkdir -p, which creates intermediate directories when and as needed. Using mkdir -p, those two commands could become one. This one:


mkdir -p "$1$/$2/info"


Note that vertical double quotes are shown here and are necessary syntax, and not angle quotes that the forum software prefers to insert.


To make that mkdir command do what you want (if I understand your request here correctly), use this command:


mkdir -p "$1 $2/info"


That command creates a directory based on whatever is in $1 and a space and whatever is in $2, and a with a subdirectory named info.


This assumes you are passing the date into the mkdir command from your Automator script as the second argument.


If you want that date stuff to happen automatically, using one argument and the current date:


mkdir -p "$1 $(date -j +"%Y%m")/info"


That generates a four digit year and a two digit month in the path. Which will sort in the expected order in Finder and elsewhere, where %m%Y won’t.


A shell script can prompt users for input using an osascript call, as needed. Automator and Shortcuts are good for some stuff, but can get in the way for other tasks. This is one of those latter areas.


PS: Here are some of the zsh shell-scripting threads mentioned earlier:

... short cut date as file name - Apple Community

... How can I append wildcards to a variable? - Apple Community

Jan 24, 2023 12:02 PM in response to Neecerp3

I’ve posted examples of using dates in shell scripts; in the zsh shell. (Similar date-related file-renaming questions over the past few weeks, mostly involving limits of Shortcuts.) Using the forum search on my nick, zsh, and the past month, should find it here in ASC in the Developer Forums community.)


In this case, the shell needs to have the mkdir path containing the / quoted, or needs to have the / escaped. Use backslash \ to quote the character /. Which means using \/ in the string. If you (also) want to use embedded spaces, it’ll be easiest to “ the whole filename string, using vertical double quotes. (This detail is mentioned in the zsh example.)


I would suggest not using MM/YY too, as that will not sort the way you probably want it to sort. I would encourage YYYY/MM, or YYYY-MM, or YYYYMM, there. Having gone through Y2K, seeing YY used anywhere just bothers me, too.

Create a Folder with the mm/yy at the end of it using Automator

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