I need a little help with automating file creation! [Solved]

I’m trying to buidling a workflow that will automate some of the tasks I do manualy when i start a new projects.

I will start by defining the project, so you get a clear understanding of my problem. :slight_smile:

The user will trigger a text input.

The input will be part of the name of a folder in a set directory, in this case, /projects.

When the folder is created, it will be given a sequential number so the name of the first folder will be “(PE0001) - Input”, the second one “(PE0002) - Input”.

Here begins the part I need help with.

When a new folder is created as I described above.

  1. Capture the folders name, ( (PE0001) - Input )
  2. Create a new OmniFocus project with the same name as the folder
  3. Create a new OmniOutliner file with the same name as the folder, and place is within the newly created folder. The location is then /projects/(PE0001) - input)

I’m not sure if this is possible. But in the source directory, /projects, there is an excel file named “Project costs” is there some way to capture the name of the folder “(PE0001) - Input” and ad it as a new sheet? the new sheet would have some simple formatting and a few formulas.

I’m looking around for a script that can help me, or maybe an Automator workflow but unfortunate I’m stuck!

Do you smart people have any suggestions to where to go from here? :smiley:

# Here's an AppleScript solution for you Linkonlawyer

# Let's assume that your projects folder is called "Projects", and is in the top level of your home folder …

set projects_folder to (path to home folder as string) & "Projects:" # Change this to the actual path of your projects folder

set resultDialogReply to display dialog "New project's name" default answer "" with title "New Project"
set project_name to text returned of resultDialogReply

tell application "Finder"
    # Get the previous project number 
    # This assumes at least 1 folder already exists "(PE0001) - project name". 
    set previous_project to last item of (sort (folders of (folder projects_folder) whose name begins with "(PE") by name)
    set previous_project_number to characters 4 thru 7 of (name of previous_project as string) as string
    # The largest existing project number is used to create the next project number, which adds +1
    set next_project_number to characters -4 thru -1 of ("0000" & (previous_project_number + 1)) as string
    set new_project_label to "(PE" & next_project_number & ") - " & project_name
    # Make the new folder in Finder
    set new_folder to make new folder at projects_folder with properties {name:new_project_label}
    reveal new_folder
end tell

# Make new project in OmniFocus

tell application "OmniFocus"
    tell default document
        make new project with properties {name:new_project_label}
    end tell
end tell

# Make new OmniOutliner document in project folder

tell application "OmniOutliner"
    set new_oo to make new document
    set oo_file_path to projects_folder & new_project_label & ":" & new_project_label & ".ooutline"
    save new_oo in file (oo_file_path)
end tell

@Linkonlawyer you should look on talk.automators.fm

1 Like

BTW, the script I wrote for you above is bigger than the field will display, so you’ll have to scroll up and down to see/select it all

1 Like

Thanks, @Jjm!

@RobertBlack Thanks, I saw that. The Script works amazingly! But I’m having problems adding the actual folder path since it’s on my Icloud drive.

I think the path should look like this:

set projects_folder to ( path to library folder from user domain as string ) & “Mobile Documents:com~apple~:Me:Projekt:(PE0084) - Test” # Change this to the actual path of your projects folder

But I’m doing something wrong since I get this Script Error :

Finder got an error: Can’t get folder “Macintosh HD:Users:david:Library:Mobile Documents:com~apple~:Me:Projekt:(PE0084) - Test”.

1 Like

Give this a try:

set projects_folder to (path to library folder from user domain as text) & "Mobile Documents:com~apple~CloudDocs:projects:"

Do not replace (path to library folder from user domain as text) because it is an AppleScript placeholder.

I have no opportunity to test it, so take it with a grain of salt.

For accessing the iCloud Drive via Terminal or script have a look at:

To be used in Applescript, the paths need to be translated a little:

1 Like

It works! Thank you so much! Both of you!

And thanks @Christian for the resource! I found the one with terminals command, but I did not realise you needed to translate it! :slight_smile:

1 Like