Apple Script to Create Folders and Word Documents?

Hi all, I’ve been going through David’s paperless course (I highly recommend it) and loved the idea of using scripts to create a preset folder structure. I also have Microsoft word documents each project always contains.

Any ideas on how I can modify this apple script below to also create a .docx document in the “Researcher Journals” folder named " Lab Journal.docx" ? I’d appreciate any help or direction. I’ve tried a few things I found googling but had no luck.

set ProjectName to "The Best Study Ever"

set loc to alias "Macintosh HD:Users:username:Downloads:Other"

tell application "Finder"
	
	set newfo to make new folder at loc with properties {name:ProjectName}
	make new folder at newfo with properties {name:"Conferences"}
	make new folder at newfo with properties {name:"Data"}
	make new folder at newfo with properties {name:"Data Analysis"}
	make new folder at newfo with properties {name:"Data Collection Materials"}
	
	set proposalfo to make new folder at newfo with properties {name:"IRB & Measures"}
	make new folder at proposalfo with properties {name:"IRB (submitted materials)"}
	make new folder at proposalfo with properties {name:"IRB (drafts)"}
	make new folder at proposalfo with properties {name:"Measures"}
	
	set proposalfo to make new folder at newfo with properties {name:"Researcher Journals"}
	make new folder at proposalfo with properties {name:"Individual Research Journals"}
	
	set proposalfo to make new folder at newfo with properties {name:"Literature"}
	make new folder at proposalfo with properties {name:"Analysis Readings"}
	make new folder at proposalfo with properties {name:"Main Points Articles"}
	make new folder at proposalfo with properties {name:"PDFs of Articles"}
	
end tell

If it’s ok if the word document is empty, you can do this:

do shell script “touch ‘Lab Journal.docx’”

Yes, the word document can be empty.

Hm I tried

set proposalfo to make new folder at newfo with properties {name:"Researcher Journals"}
	make new folder at proposalfo with properties {name:"Individual Research Journals"} 
	touch ‘Lab Journal.docx’

and tried placing touch ‘Lab Journal.docx’ in various locations but keep getting an error. Where should I place this?

I also tried the full do shell script “touch ‘Lab Journal.docx’” but keep getting Syntax Error Expected end of Line

I feel I’m getting close, I just need to know how to grab that variable name set for the project early on. Using the code below I get the word doc to create, but it’s named ’ProjectName' lab journal instead of taking the actual Project name to name the file.

set ProjectName to "First-gen Study 19"

set loc to alias "Macintosh HD:Users:username:Downloads:Other"

tell application "Finder"
	
	set newfo to make new folder at loc with properties {name:ProjectName}
	make new folder at newfo with properties {name:"Conferences"}
	make new folder at newfo with properties {name:"Data"}
	make new folder at newfo with properties {name:"Data Analysis"}
	make new folder at newfo with properties {name:"Data Collection Materials"}
	
	set proposalfo to make new folder at newfo with properties {name:"IRB & Measures"}
	make new folder at proposalfo with properties {name:"IRB (submitted materials)"}
	make new folder at proposalfo with properties {name:"IRB (drafts)"}
	make new folder at proposalfo with properties {name:"Measures"}
	
	set proposalfo to make new folder at newfo with properties {name:"Researcher Journals"}
	make new folder at proposalfo with properties {name:"Individual Research Journals"}
	make new file at proposalfo with properties {name:"'ProjectName' lab journal.docx"}
	
	set proposalfo to make new folder at newfo with properties {name:"Literature"}
	make new folder at proposalfo with properties {name:"Analysis Readings"}
	make new folder at proposalfo with properties {name:"Main Points Articles"}
	make new folder at proposalfo with properties {name:"PDFs of Articles"}
	
end tell

Got it!

set ProjectName to "First-gen Study 5"

set loc to alias "Macintosh HD:Users:username:Downloads:Other"

tell application "Finder"
	
	set newfo to make new folder at loc with properties {name:ProjectName}
	make new folder at newfo with properties {name:"Conferences"}
	make new folder at newfo with properties {name:"Data"}
	make new folder at newfo with properties {name:"Data Analysis"}
	make new folder at newfo with properties {name:"Data Collection Materials"}
	
	set proposalfo to make new folder at newfo with properties {name:"IRB & Measures"}
	make new folder at proposalfo with properties {name:"IRB (submitted materials)"}
	make new folder at proposalfo with properties {name:"IRB (drafts)"}
	make new folder at proposalfo with properties {name:"Measures"}
	
	set proposalfo to make new folder at newfo with properties {name:"Researcher Journals"}
	make new folder at proposalfo with properties {name:"Individual Research Journals"}
	make new file at proposalfo with properties {name:ProjectName & " lab journal.docx"}
	
	set proposalfo to make new folder at newfo with properties {name:"Literature"}
	make new folder at proposalfo with properties {name:"Analysis Readings"}
	make new folder at proposalfo with properties {name:"Main Points Articles"}
	make new folder at proposalfo with properties {name:"PDFs of Articles"}
	
end tell

It looks like you have smart quotes in the script sample you posted here, the single quotes need to be straight :slight_smile:

1 Like