Tag Maintenance in Things

Screenshot of a script editor with a partially visible AppleScript code titled "Add Tags Based on Family Members". The code includes commands to set variables for family members, iterate through areas and to-dos, and conditionally add tags to items based on the presence of family member names within the item titles. The user interface shows the script editing window with options to run, stop, and share the script, and there is a description field below the code that is empty.

I shared a post on Mastodon about using ChatGPT to create small scripts to deal with the various friction points in my digital life. I put together a short post sharing the script I use to maintain my tags in Things.

Moving from OmniFocus

When I was using OmniFocus, I used tags a lot for driving the different custom perspectives that I used throughout the day.

Since I switched to Things, I haven’t been using tags significantly, but I think I might want to. However, I have plenty of action items already in Things that don’t have tags. I also have various automations set up that don’t assign tags, and (for reasons) I don’t want to change them. So, I decided to look into scripting a solution.

Script

I checked out the Things documentation for AppleScript and decided to ask ChatGPT for help.

My goal was to make sure any action item in an Area of Things would get tagged with the tag for that Area. I also wanted to make sure that any action item that mentioned one of my family members would get a tag for that person.

We went back and forth a few times, troubleshooting the code and making sure it would work with my use case, and finally landed on a solution that works great for me. I am happy to share it here with you. But first, I want to point out that this script doesn’t create new tags. The tags you build into the script must already exist in Things.

AppleScript for Tag Maintenance

tell application "Things3"
	set theTag to "AreaTag" -- Replace 'AreaTag' with the tag you want to apply to tasks in a specific area. The tag must already exist in Things; this script will not create new tags.
	repeat with ccToDo in to dos of area "AreaName" -- Replace 'AreaName' with the name of the area in Things 3 where you want to apply the tag. The Area must already exist in Things; this script will not create new Areas.
		set theTags to tag names of ccToDo
		if theTags does not contain theTag then
			set tag names of ccToDo to theTags & ", " & theTag -- Adds the specified tag to the task if it's not already there.
		end if
	end repeat
end tell

tell application "Things3"
	set theTag to "AreaTag" -- Replace 'AreaTag' with the tag you want to apply to tasks in a specific area. The tag must already exist in Things; this script will not create new tags.
	repeat with ccToDo in to dos of area "AreaName" -- Replace 'AreaName' with the name of the area in Things 3 where you want to apply the tag. The Area must already exist in Things; this script will not create new Areas.
		set theTags to tag names of ccToDo
		if theTags does not contain theTag then
			set tag names of ccToDo to theTags & ", " & theTag -- Adds the specified tag to the task if it's not already there.
		end if
	end repeat
end tell

tell application "Things3"
	set theTag to "AreaTag" -- Replace 'AreaTag' with the tag you want to apply to tasks in a specific area. The tag must already exist in Things; this script will not create new tags.
	repeat with ccToDo in to dos of area "AreaName" -- Replace 'AreaName' with the name of the area in Things 3 where you want to apply the tag. The Area must already exist in Things; this script will not create new Areas.
		set theTags to tag names of ccToDo
		if theTags does not contain theTag then
			set tag names of ccToDo to theTags & ", " & theTag -- Adds the specified tag to the task if it's not already there.
		end if
	end repeat
end tell

tell application "Things3"
	set theTag to "AreaTag" -- Replace 'AreaTag' with the tag you want to apply to tasks in a specific area. The tag must already exist in Things; this script will not create new tags.
	repeat with ccToDo in to dos of area "AreaName" -- Replace 'AreaName' with the name of the area in Things 3 where you want to apply the tag. The Area must already exist in Things; this script will not create new Areas.
		set theTags to tag names of ccToDo
		if theTags does not contain theTag then
			set tag names of ccToDo to theTags & ", " & theTag -- Adds the specified tag to the task if it's not already there.
		end if
	end repeat
end tell

tell application "Things3"
	set theTag to "AreaTag" -- Replace 'AreaTag' with the tag you want to apply to tasks in a specific area. The tag must already exist in Things; this script will not create new tags.
	repeat with ccToDo in to dos of area "AreaName" -- Replace 'AreaName' with the name of the area in Things 3 where you want to apply the tag. The Area must already exist in Things; this script will not create new Areas.
		set theTags to tag names of ccToDo
		if theTags does not contain theTag then
			set tag names of ccToDo to theTags & ", " & theTag -- Adds the specified tag to the task if it's not already there.
		end if
	end repeat
end tell

tell application "Things3"
	set familyMembers to {"FamilyMember1", "FamilyMember2", "FamilyMember3"} -- Add family member names here. Tags must already exist in Things for each family member; this script will not create new tags.
	repeat with eachArea in areas
		repeat with ccToDo in to dos of eachArea
			set theTitle to name of ccToDo
			set theTags to tag names of ccToDo
			repeat with eachMember in familyMembers
				if (theTitle contains eachMember or theTitle contains (eachMember & "'s")) and (theTags does not contain eachMember) then
					set tag names of ccToDo to theTags & ", " & eachMember
				end if
			end repeat
		end repeat
	end repeat
end tell

Automating It

After testing the code in Script Editor, I created a new Keyboard Maestro Macro to run the script every day at 5 pm. While there are a ton of different triggers and schedules you could use to run the script, this works for me as daily is plenty fast enough for me.

Closure

I have always kept an eye out for the little pain points in my digital day that could be improved (usually with automation apps), but these days, ChatGPT is helping extend that toolkit into scripting, which I have never quite been able to use before.

I’d love to hear about your experiences with task management and automation. Have you tried scripting in your workflow? Feel free to share your stories or ask questions in the comments below.

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.