Skip to content

Instantly share code, notes, and snippets.

@lushkovsky-s
Created February 25, 2025 14:12
Show Gist options
  • Save lushkovsky-s/de97a1af457bbdc7859726004dd77a90 to your computer and use it in GitHub Desktop.
Save lushkovsky-s/de97a1af457bbdc7859726004dd77a90 to your computer and use it in GitHub Desktop.
Get Cursor/VSCode workspace ID by path (tested on Mac)
# get_cursor_workspace_id.sh - Get Cursor workspace ID for a given path
# Check if path argument is provided
if [ $# -ne 1 ]; then
echo "Usage: $0 /path/to/workspace" >&2
exit 1
fi
# Normalize input path (remove trailing slash)
SEARCH_PATH="${1%/}"
# Expand tilde in path
if [[ "$SEARCH_PATH" == "~"* ]]; then
SEARCH_PATH="${SEARCH_PATH/#\~/$HOME}"
fi
# Look for workspace folders in Cursor storage
CURSOR_STORAGE_DIR="$HOME/Library/Application Support/Cursor/User/workspaceStorage"
# Try alternative location if not found
if [ ! -d "$CURSOR_STORAGE_DIR" ]; then
CURSOR_STORAGE_DIR="$HOME/Library/Application Support/Cursor/workspaceStorage"
if [ ! -d "$CURSOR_STORAGE_DIR" ]; then
echo "Error: Cursor workspace storage not found" >&2
exit 1
fi
fi
# Find workspace ID for the specified path
for dir in "$CURSOR_STORAGE_DIR"/*; do
if [ ! -d "$dir" ]; then
continue
fi
dir_id=$(basename "$dir")
# Check if workspace.json exists and extract folder path
if [ -f "$dir/workspace.json" ]; then
folder_path=$(grep -o '"folder":[^,]*' "$dir/workspace.json" 2>/dev/null | sed 's/"folder": "file:\/\/\///g' | sed 's/"//g')
if [ -n "$folder_path" ]; then
# Add leading slash if needed
if [[ $folder_path == Users/* ]]; then
folder_path="/$folder_path"
fi
# Remove trailing slash
folder_path="${folder_path%/}"
# Check for exact path match
if [ "$folder_path" = "$SEARCH_PATH" ]; then
echo "$dir_id"
exit 0
fi
fi
fi
done
# No workspace found
echo "Error: No workspace found for path: $SEARCH_PATH" >&2
exit 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment