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

How to create subfolder sets for multiple existing folders with drag and drop using Apple Script

I have multiple folders. I want to give each of them the same subfolders set (see screenshot below) by simply dropping all the existing folders onto an apple script application.

MacBook Pro

Posted on Sep 30, 2019 4:35 PM

Reply
Question marked as Best reply

Posted on Sep 30, 2019 6:38 PM

I created a Test2 folder to contain the folders to drop on the AppleScript. Looks like this:



After I drag and drop the three folders onto the AppleScript drop application.



The backslashes are escapes introduced by the tree application, but do not appear in the Finder, or in the Terminal. Here is the AppleScript that is saved as an Application to the Desktop, and on which you drop folders:


use scripting additions

property parent_folder : {"Stage 1 Feasibility", "Stage 2 Pre-Lodgement", "Stage 3 Prepare and Lodge", "Stage 4 Post-Lodgement"}
property subfolders : {"Handover Files", "Project Files"}

on open dropped_items
	
	repeat with afolder in dropped_items
		set pfolder to POSIX path of afolder
		repeat with aparent in parent_folder
			repeat with asub in subfolders
				do shell script "mkdir -p " & pfolder's quoted form & "/" & aparent's quoted form & "/" & asub's quoted form
			end repeat
		end repeat
	end repeat
	return
	
end open


Tested on macOS Mojave 10.14.6 (18G103).

4 replies
Question marked as Best reply

Sep 30, 2019 6:38 PM in response to reinierh

I created a Test2 folder to contain the folders to drop on the AppleScript. Looks like this:



After I drag and drop the three folders onto the AppleScript drop application.



The backslashes are escapes introduced by the tree application, but do not appear in the Finder, or in the Terminal. Here is the AppleScript that is saved as an Application to the Desktop, and on which you drop folders:


use scripting additions

property parent_folder : {"Stage 1 Feasibility", "Stage 2 Pre-Lodgement", "Stage 3 Prepare and Lodge", "Stage 4 Post-Lodgement"}
property subfolders : {"Handover Files", "Project Files"}

on open dropped_items
	
	repeat with afolder in dropped_items
		set pfolder to POSIX path of afolder
		repeat with aparent in parent_folder
			repeat with asub in subfolders
				do shell script "mkdir -p " & pfolder's quoted form & "/" & aparent's quoted form & "/" & asub's quoted form
			end repeat
		end repeat
	end repeat
	return
	
end open


Tested on macOS Mojave 10.14.6 (18G103).

Sep 30, 2019 6:03 PM in response to reinierh

This is what I have so far, but I'm not sure how to create the folders within the subfolders as per the set above.


on open droppings


repeat with everyDrop in droppings


if (info for everyDrop)'s folder is true then


--make two folders


tell application "Finder"


make new folder at (everyDrop as text) with properties {name:"Stage 1 Feasibility"}


make new folder at (everyDrop as text) with properties {name:"Stage 2 Pre Lodgement"}


make new folder at (everyDrop as text) with properties {name:"Stage 3 Prepare and Lodge"}


make new folder at (everyDrop as text) with properties {name:"Stage 4 Post-Lodgement"}



end tell


end if


end repeat


end open




on run


display dialog "Drop some folders here to add Originals and Scans folders" buttons {"Aye Aye"} default button "Aye Aye"


end run

How to create subfolder sets for multiple existing folders with drag and drop using Apple Script

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