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

(*
Things 3 Tag Maintenance Script
Version: 1.3
Created by: Mike Burke (https://www.themikeburke.com) and ChatGPT
Last Updated: 2024-01-19

License: MIT
Copyright (c) 2024 Mike Burke
Permission is hereby granted to use, copy, modify, and share this script freely,
provided the above copyright and attribution notices are preserved.
Full license text: https://opensource.org/licenses/MIT

Description:
This script automates tag management in Things 3 by ensuring tasks within specific Areas are tagged with their corresponding Area tags and that tasks mentioning family members are properly tagged. It helps maintain consistent task organization and improves findability within Things 3.

Functionality:
1. Area Tag Management:
   a. Checks each task within a specified Area
   b. Verifies if the Area's corresponding tag is applied
   c. Adds the Area tag if not present
   d. Preserves any existing tags while adding new ones
   e. Process can be duplicated for multiple Areas (see Usage notes)

2. Family Member Tag Management:
   a. Scans all tasks across all Areas
   b. Checks task titles for family member names
   c. Applies corresponding family member tags when names are found
   d. Handles both direct names and possessive forms (e.g., "John" and "John's")
   e. Preserves existing tags while adding family member tags

Usage:
1. Configure Area Section:
   - Replace 'AreaTag' with your desired tag name
   - Replace 'AreaName' with your Things 3 Area name
   - Duplicate the Area code block for each Area you want to manage
   
2. Configure Family Member Section:
   - Replace 'FamilyMember1', 'FamilyMember2', etc. with actual family member names
   - Ensure corresponding tags exist in Things 3 for each family member

3. Run script to:
   - Apply Area tags to all tasks in specified Areas
   - Apply family member tags to relevant tasks across all Areas

Note: 
- Requires Things 3 for macOS
- All tags must exist in Things 3 before running the script
- Script will not create new tags or Areas
- Areas are processed independently to ensure reliable tag application
- Family member names are case-sensitive
*)

-- Area Tag Management Section
-- Duplicate this block for each Area you want to manage, updating AreaTag and AreaName accordingly
tell application "Things3"
    -- Set the tag to be applied to tasks in this Area
    set theTag to "AreaTag" -- Replace with your Area's tag (must exist in Things)
    
    -- Process each task (to do) in the specified Area
    repeat with ccToDo in to dos of area "AreaName" -- Replace with your Area's name
        -- Get current tags for the task
        set theTags to tag names of ccToDo
        
        -- Check if Area tag is missing and add if needed
        if theTags does not contain theTag then
            set tag names of ccToDo to theTags & ", " & theTag
        end if
    end repeat
end tell

-- Family Member Tag Management Section
tell application "Things3"
    -- Define list of family members to check for in task titles
    set familyMembers to {"FamilyMember1", "FamilyMember2", "FamilyMember3"} -- Replace with actual names
    
    -- Process all Areas
    repeat with eachArea in areas
        -- Check each task in current Area
        repeat with ccToDo in to dos of eachArea
            -- Get task title and current tags
            set theTitle to name of ccToDo
            set theTags to tag names of ccToDo
            
            -- Check for each family member's name in task title
            repeat with eachMember in familyMembers
                -- Look for name or possessive form (name's) and verify tag isn't already applied
                if (theTitle contains eachMember or theTitle contains (eachMember & "'s")) and (theTags does not contain eachMember) then
                    -- Add family member tag while preserving existing tags
                    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.