Last active
July 24, 2025 12:40
-
-
Save dzogrim/21b57261ac80b161e8c95d164f2524c3 to your computer and use it in GitHub Desktop.
Set new Spotlight window position to the computed coordinates and size
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# SPDX-License-Identifier: MIT | |
# SPDX-FileCopyrightText: 2015-2025 dzogrim | |
# SPDX-FileContributor: dzogrim <[email protected]> | |
# ----------------------------------------------------------------------------- | |
# reset_spotlight_position.sh | |
# ----------------------------------------------------------------------------- | |
# Description: | |
# Re-centers the macOS Spotlight search bar on the main screen. | |
# Optionally disables onboarding/suggestions and resets corrupted positioning. | |
# | |
# Usage: | |
# ./reset_spotlight_position.sh → safe reset (recommended) | |
# ./reset_spotlight_position.sh --force → full reset (includes .plist removal) | |
# | |
# Requirements: | |
# - macOS (tested on macOS 15.5 Sequoia) | |
# - Accessibility access for Terminal (osascript) | |
# ----------------------------------------------------------------------------- | |
# Author: Sebastien L. | |
# Maintainer: dzogrim (Sébastien L.) — MIT License | |
# License: MIT | |
# ----------------------------------------------------------------------------- | |
set -euo pipefail | |
# Default Spotlight window size | |
WIDTH=600 | |
HEIGHT=52 | |
# Handle --force .plist deletion mode | |
FORCE_MODE=false | |
if [[ "${1:-}" == "--force" ]]; then | |
FORCE_MODE=true | |
fi | |
# Get main screen resolution via AppleScript | |
IFS=' ' read -r SCREEN_WIDTH SCREEN_HEIGHT <<< "$( | |
osascript -e ' | |
tell application "Finder" | |
set screenBounds to bounds of window of desktop | |
set w to item 3 of screenBounds | |
set h to item 4 of screenBounds | |
return w & " " & h | |
end tell' | tr -d ',' | xargs | |
)" | |
# Compute centered position | |
X=$(( (SCREEN_WIDTH - WIDTH) / 2 )) | |
Y=$(( (SCREEN_HEIGHT - HEIGHT) / 2 - 40 )) | |
# Apply reset logic | |
if $FORCE_MODE; then | |
echo "⚠️ Forcing full Spotlight prefs reset ..." | |
rm -f ~/Library/Preferences/com.apple.Spotlight.plist | |
else | |
defaults delete com.apple.Spotlight lastVisibleScreenRect 2>/dev/null || true | |
fi | |
# Set new Spotlight window position to the computed coordinates and size. | |
defaults write com.apple.Spotlight lastVisibleScreenRect -string "{{${X}, ${Y}}, {${WIDTH}, ${HEIGHT}}}" | |
# Mark the Spotlight onboarding screen as already seen, to avoid the intro popup. | |
defaults write com.apple.Spotlight PresentationModeMenuSeen -bool true | |
# Disable Spotlight suggestions (e.g. web results, Siri suggestions). | |
defaults write com.apple.Spotlight SuggestionsEnabled -bool false | |
# Disable Lookup (dictionary) suggestions from Apple servers. | |
defaults write com.apple.lookup.shared LookupSuggestionsDisabled -bool true | |
# Checks the syntax of the Spotlight preferences file to ensure it is a valid property list (plist) file. | |
plutil -lint ~/Library/Preferences/com.apple.Spotlight.plist | |
# Restart the user-level preferences daemon so changes are picked up immediately. | |
killall cfprefsd 2>/dev/null || true | |
# Restart the SystemUIServer, which controls elements like Spotlight UI. | |
killall SystemUIServer 2>/dev/null || true | |
echo "✅ Spotlight repositioned to {${X}, ${Y}} on screen ${SCREEN_WIDTH}x${SCREEN_HEIGHT}" | |
# Open System Settings at Spotlight section | |
open "x-apple.systempreferences:com.apple.preference.spotlight" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment