Skip to content

Instantly share code, notes, and snippets.

@jvarn
Created October 23, 2025 05:37
Show Gist options
  • Save jvarn/f836801052698cf0b77703c93f7ebb24 to your computer and use it in GitHub Desktop.
Save jvarn/f836801052698cf0b77703c93f7ebb24 to your computer and use it in GitHub Desktop.
Reinstall Zotero When the Safari Extension Disappears
#!/usr/bin/env bash
set -euo pipefail
APP_NAME="Zotero.app"
APP_PATH="/Applications/${APP_NAME}"
TMP_DMG="/tmp/Zotero_latest.dmg"
DOWNLOAD_URL="https://www.zotero.org/download/client/dl?channel=release&platform=mac"
# Quit Zotero if running
quit_zotero() {
if pgrep -x "Zotero" >/dev/null; then
echo "- Zotero is currently running. Quitting..."
osascript -e 'tell application "Zotero" to quit'
# Wait until process fully exits
while pgrep -x "Zotero" >/dev/null; do
sleep 1
done
echo "- Zotero closed."
fi
}
echo "- Quitting Zotero if running..."
quit_zotero
echo "- Downloading Zotero latest version..."
curl -L --output "${TMP_DMG}" "${DOWNLOAD_URL}"
echo "- Mounting disk image..."
MOUNT_OUTPUT=$(hdiutil attach "${TMP_DMG}" -nobrowse)
MOUNT_POINT=$(echo "$MOUNT_OUTPUT" | grep -o '/Volumes/[^"]*')
if [ -z "${MOUNT_POINT}" ]; then
echo "Could not determine mount point; exiting."
exit 1
fi
echo "- Mounted at ${MOUNT_POINT}"
echo "- Removing old version (if exists)..."
if [ -d "${APP_PATH}" ]; then
echo "- Moving ${APP_PATH} to Trash"
mv "${APP_PATH}" ~/.Trash/ || sudo mv "${APP_PATH}" ~/.Trash/
fi
echo "- Copying new version to /Applications..."
if cp -R "${MOUNT_POINT}/${APP_NAME}" /Applications/; then
echo "- Copied new version."
else
echo "Copy failed — trying with sudo."
sudo cp -R "${MOUNT_POINT}/${APP_NAME}" /Applications/
fi
echo "- Unmounting disk image..."
hdiutil detach "${MOUNT_POINT}" -quiet
echo "- Cleaning up..."
rm -f "${TMP_DMG}"
echo "- Installation complete. Launching Zotero..."
open -a "Zotero"
echo "- Zotero reinstalled and launched. Check Safari → Settings → Extensions if needed."
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment