By Manny Fernandez

May 3, 2020

My Jobs Script and How to Automate It

For years and years, I would create a folder for a customer, then I would create a sub folder for a job and then inside of that sub folder, I would throw files.  No rhyme or reason.  I would have folders named Docs or Doc or docs or doc and there was no consistency.  One day probably in 2004, I said to my self,  “Self, you are going to fix this insanity today come hell or high water”  Thus began my addiction to all things Workflow.

Since then, many people have asked me how I keep my files organized.  Here is what I do.

Explanation of my script

  1. When in Finder i type  ⌘ 8  (Command 8)
  2. The script asks me the Job Name , here I can type something like DC Firewall Deployment and hit enter.
  3. Then it prompts me for the Customer Name
  4. Then I am prompted for today’s date.
  5. Next it prompts me for the location I want to save the folder.
  6. It then creates my folder structure in the location I gave it
  7. And lastly, it creates a new Evernote Note containing the Company Name-Project Name and then the path to where the file is located.

This scripts was created when I was doing more delivery of services where sometimes I had 12 projects going at the same time.  The script included prompt to have it create a OmniFocus project where it would look for a text file and every new line was considered a Task and was added to my task manager as such.  However that is NOT the case anymore so I removed it.

2020-05-03_20-51-41
Job Name Prompt
2020-05-03_20-51-58
Customer Name Prompt
2020-05-03_20-52-12
Here is the date prompt. I use TextExpander shortcut to enter today’s date

 

2020-05-03_20-52-29
Location prompt. I put on Desktop for ease of viewing
2020-05-03_20-59-16
This is the `tree` output of the final folder and sub-folders after the script runs.
2020-05-03_21-53-08
GUI Representation of the Folder Structure post-script

 

2020-05-03_20-56-04
Screenshot of Evernote Note Created by Script

 

The Script

Here is the AppleScript that gets run when I hit the shortcut keys of ⌘ 8

on run {input, parameters}

-- Sets up the JobName, CustomerName and location by asking the user

set JobName to text returned of (display dialog "Please enter Job Name:" default answer "Job_Name")
set Customer to text returned of (display dialog "Customer Name:" default answer "Customer")
set DateNow to text returned of (display dialog "Please enter Date:" default answer "Now")
set loc to choose folder "Choose Parent Folder Location"


-- Sets the filename to be used concatinated with date

set newfoldername to DateNow & "-" & JobName
set customer2 to Customer & "-" & JobName

tell application "Finder"

--Parent Directory Structure

set dir_1 to make new folder at loc with properties {name:newfoldername}
set dir_2 to make new folder at dir_1 with properties {name:"Caps"}
set dir_3 to make new folder at dir_1 with properties {name:"Configs"}
set dir_4 to make new folder at dir_1 with properties {name:"Diagrams"}
set dir_5 to make new folder at dir_1 with properties {name:"Documents"}
set dir_6 to make new folder at dir_1 with properties {name:"Scripts"}

-- Sub-Folder structure

set sub_3_1 to make new folder at dir_3 with properties {name:"Backups"}
set sub_3_2 to make new folder at dir_3 with properties {name:"Logs"}
set sub_3_3 to make new folder at dir_3 with properties {name:"Sites"}
set sub_3_4 to make new folder at dir_3 with properties {name:"Worksheets"}

set sub_4_1 to make new folder at dir_4 with properties {name:"Logos"}
set sub_4_2 to make new folder at dir_4 with properties {name:"Screenshots"}
set sub_4_3 to make new folder at dir_4 with properties {name:"Network Diagrams"}

set sub_5_1 to make new folder at dir_5 with properties {name:"Customer"}
set sub_5_2 to make new folder at dir_5 with properties {name:"Deliverable"}
set sub_5_3 to make new folder at dir_5 with properties {name:"License"}
set sub_5_4 to make new folder at dir_5 with properties {name:"Certificates"}
set sub_5_5 to make new folder at dir_5 with properties {name:"Fortinet"}
set sub_5_6 to make new folder at dir_5 with properties {name:"Validation"}
set sub_5_7 to make new folder at dir_5 with properties {name:"Scripts"}


-- Creates sub-folders under \Modcomp

set sub2_5_1 to make new folder at sub_5_5 with properties {name:"BoMs"}
set sub2_5_2 to make new folder at sub_5_5 with properties {name:"Quotes"}
set sub2_5_3 to make new folder at sub_5_5 with properties {name:"Private"}
set sub2_5_4 to make new folder at sub_5_5 with properties {name:"SoW"}
set sub2_5_5 to make new folder at sub_5_5 with properties {name:"Project Docs"}
set sub2_5_6 to make new folder at sub_5_5 with properties {name:"Standard"}
set sub2_5_7 to make new folder at sub_5_5 with properties {name:"Worksheet"}

-- Set variable to be used by Evernote

set custfldr to the loc as text

end tell

tell application "Finder"
set the clipboard to the loc as text
end tell

tell application id "com.evernote.Evernote"
create note with text custfldr title customer2 notebook "Inbox"
end tell

return input
end run

Creating the Action

Now I will show you how I automate the scripts.  First launch Automator on the macOS box.

2020-05-03_20-36-56

Once you launch Automator choose Quick Action and then Choose

2020-05-03_20-37-50

Once you get to the following screen, change the Workflow receives to no input in any application.  Then scroll down on the middle column until you find Run AppleScript and drag that over to the right underneath the no input section.

2020-05-03_20-38-51

You will need to replace all the text in the Run AppleScript section with my script (above)

You will see that the text appears in purple.  Click the little hammer icon and it will test your script and debug it.  Once complete, you will see the color change.  Save it with a name.  I chose Workflow11

2020-05-03_20-40-35

 

Creating a Shortcut

Now that we have created the Quick Action and added the AppleScript we can now create a keyboard shortcut.

2020-05-03_20-40-54

Go to System Preferences  then choose Keyboard

2020-05-03_20-41-17

  1. Choose Shortcuts on the top tabs.
  2. Then choose Services on the left
  3. Scroll down to the name you saved it as Workflow11 in my case.
  4. Assign a keystroke.  In my case ⌘ 8

Now you can open Finder and type your keystroke you assigned.

 

Hope this helps

Recent posts

  • There are many options when troubleshooting in FortiGate firewalls. ... Full Story

  • Have you ever had an IPS signature that continues... Full Story

  • Use case:  Customer has a Split Tunnel Enabled but... Full Story