Finder: Create a New Folder

Make a new folder on the desktop with the name “My Folder”.

tell application “Finder”
make new folder at (path to desktop) with properties {name:”My Folder”}
end tell


Another way to make a new folder on the desktop with the name “My Folder”. Of course you will need to change the path (“SDD:Users:Michelle:Desktop:”) to fit your needs.

tell application “Finder”
make new folder at (“SDD:Users:Michelle:Desktop:” as alias) with properties {name:”My Folder”}
end tell


Make a new folder named “My Folder” on the desktop, using a variable for the path (desktop).

tell application “Finder”
set my_desktop to path to desktop
make new folder at my_desktop with properties {name:”My Folder”}
end tell


Make a new folder named “My New Folder”. Use a variable that defines a path as alias of an existing folder called My Folder which is located on the desktop.

tell application “Finder”
set my_path to “SDD:Users:Michelle:Desktop:My Folder:” as alias
make new folder at my_path with properties {name:”My New Folder”}
end tell


Use a “try” statement to keep the script from erring if the folder it is trying to create already exists.

tell application “Finder”
try
make new folder at (path to desktop) with properties {name:”My Folder”}
end try
end tell


Understanding the code

Let’s break down the make new folder at (path to desktop) with properties {name:”My Folder”} code.
The first part, make new folder, is pretty self explanatory. This is how tell Finder that you want to make a new folder.

Followed by at, this let’s finder know that you are about to specify where the new folder should be made.

Now you need to tell finder exactly where at. The path is how you define the container folder. A container folder is the folder/path that holds a folder or in this case that will hold the new folder. As you can see from the examples, there are many ways to add the path. You can define a specific path in a variable like (“SDD:Users:Michelle:Desktop:” as alias) or you can use a more universal friendly path like (path to desktop). Parenthesis ()’s are used to help the script know which words belong together and make up one piece of information. You can also define the path in a variable. This is really helpful if you need to use the same path multiple times, especially if it might change in the future. You also may need to define the variable by asking the user to choose the location.

The last part of the code with properties {name:”My Folder”} lets you specify the name of the folder. You can use a variable here as well. If you previously created a variable like this:
set my_folder_name to “My Folder”
Then you would use the variable like this:
make new folder at (path to desktop) with properties {name:my_folder_name}

Notice how you use “” marks when you are specifying the folder name: {name:My Folder}, but if you are using a variable, you do not use “” marks: {name:my_folder_name}

Back to the Learning Guid

Add your comment

Your email address will not be published. Required fields are marked *