Apple Intelligence is now available on iPhone, iPad, and Mac!

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

AppleScript or Swift: create a subfolder inside of a folder

Hi there,


I am wanting to create the following folder structure and need a bit of a hand.


Initially I would like Finder to prompt for a file name via a dialogue box for the top folder and also where it needs to be saved:


Main top folder - this is what the prompt would fill

Folder One

MMYY - if this could automate to month month year year that would be great

Folder Two

Folder Three

Sub folder three

Folder Four

Sub folder four

Folder Five

Sub folder five



Looking for an Apple Script / Swift solution so there is something on the desktop I can click every time.


Any help appreciated.

Posted on Jan 13, 2022 1:43 PM

Reply
Question marked as Top-ranking reply

Posted on Jan 13, 2022 2:16 PM

Use the following:


tell application "Finder"

set theFolder to (choose folder)

set theName to (text returned of (display dialog "Choose a name" default answer ""))

set theFolder to make folder with properties {name:theName} at theFolder

make folder at theFolder with properties {name:"Folder One"}

make folder at theFolder with properties {name:"Folder Two"}

make folder at theFolder with properties {name:"Folder Three"}

make folder at theFolder with properties {name:"Folder Four"}

make folder at theFolder with properties {name:"Folder Five"}

make folder at folder "Folder One" of theFolder with properties {name:do shell script "date \"+%m%y\""}

make folder at folder "Folder Three" of theFolder with properties {name:"Sub folder three"}

make folder at folder "Folder Four" of theFolder with properties {name:"Sub folder four"}

make folder at folder "Folder Five" of theFolder with properties {name:"Sub folder five"}

end tell


(212003)

Similar questions

2 replies
Question marked as Top-ranking reply

Jan 13, 2022 2:16 PM in response to My_Two_Cents

Use the following:


tell application "Finder"

set theFolder to (choose folder)

set theName to (text returned of (display dialog "Choose a name" default answer ""))

set theFolder to make folder with properties {name:theName} at theFolder

make folder at theFolder with properties {name:"Folder One"}

make folder at theFolder with properties {name:"Folder Two"}

make folder at theFolder with properties {name:"Folder Three"}

make folder at theFolder with properties {name:"Folder Four"}

make folder at theFolder with properties {name:"Folder Five"}

make folder at folder "Folder One" of theFolder with properties {name:do shell script "date \"+%m%y\""}

make folder at folder "Folder Three" of theFolder with properties {name:"Sub folder three"}

make folder at folder "Folder Four" of theFolder with properties {name:"Sub folder four"}

make folder at folder "Folder Five" of theFolder with properties {name:"Sub folder five"}

end tell


(212003)

AppleScript or Swift: create a subfolder inside of a folder

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