Skip to content

Fix Bash syntax error in Mac set-login.sh script#1

Open
kylefmohr wants to merge 1 commit into
vineyardbovines:mainfrom
kylefmohr:main
Open

Fix Bash syntax error in Mac set-login.sh script#1
kylefmohr wants to merge 1 commit into
vineyardbovines:mainfrom
kylefmohr:main

Conversation

@kylefmohr

Copy link
Copy Markdown

Hi! Thanks for sharing your dotfiles, lots of very useful stuff that I'm going to steal.

Gemini found a bug in this script and I was able to reproduce it.

snippet of Gemini's output

In bash, arrays are separated by spaces or newlines, not commas.

Because of the trailing commas on lines 5 through 9, the script is searching for a folder that literally ends in .app,. When it hits the [[ -d "$APP_PATH" ]] check, the Mac will say "that doesn't exist" and silently skip adding CleanShot, Expo Orbit, noTunes, Raycast, and Rectangle.

Reproduction

To verify Gemini's assertion, I modified the script to include the apps that start on login on my Mac:

#!/bin/bash

declare -a LOGIN_ITEMS=(
    "/Applications/Loop.app"
    "/Applications/Music Decoy.app"
    "/Applications/Paste – Limitless Clipboard.app",
    "/Applications/Scroll Reverser.app",
    "/Applications/Stats.app",
)

CURRENT_ITEMS=$(osascript -e 'tell application "System Events" to get the name of every login item' 2>/dev/null)

for APP_PATH in "${LOGIN_ITEMS[@]}"; do
    echo "$APP_PATH"
    APP_NAME=$(basename "$APP_PATH" .app)

    if [[ -d "$APP_PATH" ]]; then
        if ! echo "$CURRENT_ITEMS" | grep -q "$APP_NAME"; then
            osascript -e "tell application \"System Events\" to make login item at end with properties {path:\"$APP_PATH\", hidden:false}" 2>/dev/null
        fi
    fi
done

then removed all items in System Settings > Login Items manually before running this script

This screenshot shows that the bug does in fact cause the behavior Gemini was talking about

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant