Search code examples
macosapplescriptfinder

How to create a folder (with subfolders) with Applescript


Filemaker has the ability to ake use of AppleScript.

From within Filemaker I want to create a new folder (with the name of a FileMaker field) that holds 6 subfolders.

I am a complete noob where it comes to Applescript.

This is my script so far:

tell application "FileMaker Pro Advanced"
set folder_name to cell "FolderName" of current record
end tell
tell application "Finder"
     activate
     make new folder at folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:folder_name}
end tell
tell application "Finder"
     activate
        make new folder at folder {name:folder_name} of folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:"subfolder"}
end tell

My problem is: the creation of "Subfolder1"

What is my mistake there?

Help is much appreciated


Solution

  • When you crate a new folder you can define various properties, but when refering to the folder just use the name, for example:

    make new folder at folder folder_name of folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:"subfolder"}
    

    Note that the result returned from making a new folder is a reference to that folder, so you can also do something like:

    tell application "Finder"
    
      set newFolder to (make new folder at folder "Desktop" of folder "dick" of folder "Users" of startup disk with properties {name:folder_name})
    
      make new folder at newFolder with properties {name:"subfolder"}
    
    end tell