OSX Folder Structure

I use the following folder structure to store projects in my OS X system.

2021
-06 June
–WK 21
—Project name
----Folder 1
----Folder 2
----Folder 3
----Folder 4
----Folder 5
—Project name
—Project name
—Project name
–WK 22
Can the project folder structure be automated via AppleScript allowing the flexibility to choose the month and week before making the project folder structure?

I’ve included my suggestion below. It prompts for both the day and month but that is easily changed if the day will always be “06” (which would seem unlikely).

use framework "Foundation"
use scripting additions

set baseFolder to (path to desktop as text)

set theFolders to current application's NSString's stringWithString:(POSIX path of baseFolder)
set theFolders to (theFolders's stringByAppendingPathComponent:"2021")

set dayMonth to text returned of (display dialog "Enter the desired day and month" default answer "")
if dayMonth = "" then error number -128
set theFolders to (theFolders's stringByAppendingPathComponent:dayMonth)

set weekNumber to text returned of (display dialog "Enter the week number" default answer "")
if weekNumber = "" then error number -128
set weekNumber to "WK " & weekNumber
set theFolders to (theFolders's stringByAppendingPathComponent:weekNumber)

set fileManager to current application's NSFileManager's defaultManager()
(fileManager's createDirectoryAtPath:theFolders withIntermediateDirectories:true attributes:(missing value) |error|:(missing value))

Thank you for your recommendation. The purpose of the script is to be able to automate the folder structure creation at the target directory. The target directory changes week by week, month to month, and year by year.

Let’s say I set the starting location at 2021. Can the script contain a drop-down menu to choose the month and another to chose the week?

How is this problem typically solved by creating a repeatable set of folders at a different target directory?

Example:

06JUN

–WK21
---- Target Directory 1
------(Script makes folder structure)
---- Target Directory 2
------(Script makes folder structure)

–WK22
---- Target Directory 1
------(Script makes folder structure)
---- Target Directory 2
------(Script makes folder structure)

How do you set the baseFolder to (path to desktop as text)?

A simpler way to as this question is can the AppleScript start at a specific folder location, then prompt the user to select a folder, then make the folder structure.

Just in general, AppleScripts are not started at a specific folder location. Instead, paths to items are used.

AppleScript has a choose folder command and you can set a default location:

set defaultLocation to (path to desktop)
set baseFolder to (choose folder default location defaultLocation) as text

You can get more information on choose-folder options in the Standard Additions dictionary or in the AppleScript Language Guide:

https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-DontLinkElementID_684

The above code lines can be inserted in whatever script you are using to create the folder structure. I tested these code lines in my script in post 2 and everything worked as expected.