Mirror a Folder as Project in Things

TL;DR – Hazel sees a folder tagged “Mirror_in_Things” and runs an AppleScript to create a new project in Things, and to-dos for each file with link back to the file

I use my desktop as a working space – it usually only has folders or files that are actively being used. Once I’m done with them, I usually archive them in subfolders based on tags using another Hazel rule.

Often, a new folder and its files coincides with a new project that I’m starting, and this structure serves as a useful place for me to start a new project in Things. I created the following Hazel rule and AppleScript to automate this process:

test2

Here’s what the rule looks like in Hazel:

Untitled

And here’s the embedded script:

set filepath to theFile as string

tell application "Finder" to set {dispName, nameExt, isHidden} to {displayed name, name extension, extension hidden} of alias filepath
if isHidden or nameExt is equal to "" then
	dispName
else
	(characters 1 through (-2 - (count of nameExt)) of dispName) as text
end if
set theProjectName to result


tell application "Finder" to set theFolderList to files of folder theFile as alias list

tell application "Things3"
	make new project with properties {name:theProjectName}
end tell

repeat with x in theFolderList
	
	set thePath to POSIX path of x
	
	set filepath to x as string
	
	set AppleScript's text item delimiters to {"/"}
	set thedelimitedList to every text item of thePath
	set theCount to count of thedelimitedList
	set theName to item theCount of thedelimitedList
	set theNotes to "[filepath=" & thePath & "]" & theName & "[/filepath]"
	
	tell application "Things3"
		make new to do with properties {name:theName, notes:theNotes} at beginning of project theProjectName
	end tell
	
end repeat

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s