Automator script for folder structure in right click menu.
I had a client that works with graphics and requires an easy way to create a folder standard folder structure. This ensures that all client jobs are the same structure. This task can easily be used to create a folder structure with files and resources.
To create this script I used Automator, open Automator and start a new workflow.
Select Service and click 'choose'.
This will open a blank workflow.
From here the possibilities are endless, but we want to create folders.
In the left pane, under Library select Utilities. Inside utilities double click on 'Run Shell Script'. This is how we will be creating the folder structure.
We will be using simple commands to make the structure as we desire. The commands we will be using are 'cd' and 'mkdir'. These two commands will allow us to accomplish everything we need.
*Note* one of the tricky parts of this script is getting it to run in the correct folder. To accomplish this we will set the variable for the current folder and then move to it.
#Set current directury as current path and move to it
current_path=$(dirname "$1")
cd "$current_path"
Now that we have the script running in the correct folder we can start to make our structure.
For this example, I will be using generic folder names, Folder#.
#create first upper lvl folder
mkdir Folder1
With the initial folder created we can build in that folder.
#Folders inside the first folder
mkdir Folder1/Folder2
mkdir Folder1/Folder3
That is the basis of how this script works, create a folder and then create more inside it. If we need more folders in the structure we can add folders into it.
#create Folders inside the second folder
mkdir Folder1/Folder2/Folder4
mkdir Folder1/Folder2/Folder5
mkdir Folder1/Folder2/Folder6
The only rule here is you have to create the upper-level folders before you can put the lower-level folders inside. When you put it all together it should look something like this, but the folders should be named properly.
#Set current directury as current path and move to it
current_path=$(dirname "$1")
cd "$current_path"
#Create first level folder
mkdir Folder1
#Create folders inside the first folder
mkdir Folder1/Folder2
mkdir Folder1/Folder3
#Create folders inside the second folder
mkdir Folder1/Folder2/Folder4
mkdir Folder1/Folder2/Folder5
mkdir Folder1/Folder2/Folder6
After the script has been created and saved we need to place it somewhere to make it available for use. If you would like this to just be available to the user account only, just double-click on the workflow file and install it.
If you would like to action available to any user on the machine it needs to be placed into the /Library/Services folder. This folder may not exist on your Mac, if it does not then create it and place the workflow file inside.
Now when you right click on a file or folder you will have a services section at the bottom that contains your new custom script. You can see here our action is called Folder-Creator. click this and it will create the folder structure we laid out in Automator.
This menu action will be available for all users that login to this machine. You can open and edit this task as you need, or add in other actions that suit your structure.
Please comment if you found this useful or have any questions.
No comments:
Post a Comment