Skip to content

Instantly share code, notes, and snippets.

@RhetTbull
Created March 18, 2026 15:18
Show Gist options
  • Select an option

  • Save RhetTbull/854966f6b28d6a036bd5379d5627cce0 to your computer and use it in GitHub Desktop.

Select an option

Save RhetTbull/854966f6b28d6a036bd5379d5627cce0 to your computer and use it in GitHub Desktop.
Automatically update macOS Finder Favorites sidebar to track recent project

Recent Projects in Finder Sidebar

Show your last 3 visited code projects as a Finder sidebar folder, updated automatically by zsh.

The Problem

There's no reliable public API for programmatically adding items to the macOS Finder sidebar Favorites. The old LSSharedFileList API was deprecated in macOS 10.11 and removed in 10.13. Tools like mysides no longer work on modern macOS (Sequoia).

I keep all my code projects in ~/code. I frequently want to drag files to a recently used project (I work mostly in the terminal). This shows a work-around to keep the Finder Favorites sidebar updated with the last 3 code projects I've worked on.

The Solution

Instead of fighting Finder's internals, this uses a simple workaround:

  1. A hidden folder (~/.Recent Projects/) contains numbered symlinks pointing to your most recently visited project directories
  2. A zsh chpwd hook automatically updates the symlinks whenever you cd into a subdirectory of ~/code
  3. You drag the ~/.Recent Projects folder to your Finder sidebar once — after that, it stays current automatically

The result looks like this in Finder:

.Recent Projects/
  1 applescripts   → ~/code/applescripts
  2 osxphotos      → ~/code/osxphotos
  3 aoc2024        → ~/code/aoc2024

Setup

1. Create the folder

mkdir -p "$HOME/.Recent Projects"

2. Add this to your .zshrc

# Recent Projects — keep Finder sidebar folder with last 3 ~/code subdirs
RECENT_PROJECTS_DIR="$HOME/.Recent Projects"
RECENT_PROJECTS_HISTORY="$RECENT_PROJECTS_DIR/.history"

_update_recent_projects() {
  local current="$PWD"
  local code_dir="$HOME/code"

  # Only track direct children of ~/code
  [[ "$current" == "$code_dir"/* ]] || return
  local project="${current#$code_dir/}"
  project="${project%%/*}"
  [[ -n "$project" && -d "$code_dir/$project" ]] || return

  # Update history: remove existing entry, prepend new one, keep 3
  touch "$RECENT_PROJECTS_HISTORY"
  local tmp
  tmp=$(grep -vx "$project" "$RECENT_PROJECTS_HISTORY" 2>/dev/null | head -2)
  { echo "$project"; [[ -n "$tmp" ]] && echo "$tmp"; } > "$RECENT_PROJECTS_HISTORY"

  # Remove old symlinks, recreate numbered ones
  for lnk in "$RECENT_PROJECTS_DIR"/[1-3]\ *; do
    [[ -L "$lnk" ]] && command rm -f "$lnk"
  done
  local i=1
  while IFS= read -r proj; do
    [[ -n "$proj" ]] || continue
    ln -sf "$code_dir/$proj" "$RECENT_PROJECTS_DIR/$i $proj"
    ((i++))
    [[ $i -gt 3 ]] && break
  done < "$RECENT_PROJECTS_HISTORY"
}

autoload -Uz add-zsh-hook
add-zsh-hook chpwd _update_recent_projects

3. Add the folder to Finder sidebar

  1. Open Finder
  2. Press Cmd+Shift+G and type ~/.Recent Projects
  3. Drag the .Recent Projects folder proxy icon to the Favorites section of your sidebar

How It Works

  • chpwd hook: zsh calls _update_recent_projects every time the working directory changes — whether via cd, pushd, popd, or any other mechanism.
  • Project detection: The function checks if the current directory is under ~/code/. If so, it extracts just the top-level project name (e.g., cd ~/code/osxphotos/tests tracks osxphotos).
  • History file: ~/.Recent Projects/.history stores project names in most-recent-first order. On each visit, the current project is moved to the top and the list is trimmed to 3.
  • Numbered symlinks: After updating history, old symlinks (1 ..., 2 ..., 3 ...) are removed and recreated. The numbering keeps the most recent project visually sorted first in Finder.

Customization

  • Change the tracked directory: Replace $HOME/code in the code_dir variable with any parent directory you want to track.
  • Change the number of projects: Replace head -2 with head -N-1 and the [1-3] glob with [1-N] where N is the desired count.
  • Change the folder location: Update RECENT_PROJECTS_DIR to wherever you'd like the symlinks to live.

Requirements

  • macOS (tested on Sequoia 15)
  • zsh (default shell on macOS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment