Saturday, November 27, 2021

#1 2021-11-21 07:34:44 pm

Sepa
Member
Registered: 2020-10-09
Posts: 34

Adding subfolders

I am testing the following script. Is it possible to add subfolders to the folder property folerNames?

For example:
Concept 1 (Top folder)
Assets (Subfolder)
Production (Subfolder)
Review (Subfolder)
Trash (Subfolder)


property folderNames : {"Concept 1", "Concept 2", "Concept 3", "Concept 4"}

set posixPath to text 1 thru -2 of (the clipboard as string)
set hfsPath to posixPath as POSIX file as text

tell application "Finder"
   
    repeat with i in folderNames
        set name of (make new folder at (hfsPath)) to i
    end repeat
   
end tell

Last edited by Sepa (2021-11-21 08:23:56 pm)


Filed under: Subfolders, applescript

Offline

 

#2 2021-11-22 02:03:17 am

alastor933
Member
From:: Utrecht, NL
Registered: 2008-09-12
Posts: 587

Re: Adding subfolders

The same question was asked & answered here.

Offline

 

#3 2021-11-22 05:33:06 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2154

Re: Adding subfolders

set name of (make new folder at folder hfsPath) to contents of i


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#4 2021-11-22 05:41:54 am

Sepa
Member
Registered: 2020-10-09
Posts: 34

Re: Adding subfolders

KniazidisR wrote:

set name of (make new folder at folder hfsPath) to contents of i



Can you share an example, please? I am not sure how to set the i.

Offline

 

#5 2021-11-22 05:47:55 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11755
Website

Re: Adding subfolders

The shell provides a pretty convenient way to do that

Applescript:

set posixPath to text 1 thru -2 of (the clipboard)
set folderStructure to quoted form of posixPath & "/{'Concept 1','Concept 2','Concept 3','Concept 4'}/{Assets,Production,Review,Trash}"
do shell script "/bin/mkdir -p " & folderStructure

Side note: Getting the path from the clipboard is not reliable. I would prefer choose folder

Last edited by StefanK (2021-11-22 05:51:20 am)


regards

Stefan

Offline

 

#6 2021-11-22 07:14:23 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2154

Re: Adding subfolders

Sepa wrote:

Can you share an example, please? I am not sure how to set the i.



@StefanK provided best solution. Other choice (using your example logic) was this:

Applescript:


property folderNames : {"Concept 1", "Concept 2", "Concept 3", "Concept 4"}
property subFolderNames : {"Assets", "Production", "Review", "Trash"}

set hfsPath to (choose folder) as text

tell application "Finder"
   
   repeat with i in folderNames
       set aFolder to make new folder at folder hfsPath with properties {name:(contents of i)}
       repeat with subFolderName in subFolderNames
           make new folder at aFolder with properties {name:(contents of subFolderName)}
       end repeat
   end repeat
   
end tell

Note: I am not sure, but it seems to me, it can be useful if you don't want to grant full disk access to mkdir command (for some special locations). But, as I sad, generally I see the solution from @StefanK better than Finder solution.

Last edited by KniazidisR (2021-11-22 07:29:38 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)