Skip to content

Skip Spotify AppleScript when Spotify isn't installed (fix #8)#23

Open
shobhit99 wants to merge 1 commit into
mainfrom
claude/fix-issue-8-spotify-prompt
Open

Skip Spotify AppleScript when Spotify isn't installed (fix #8)#23
shobhit99 wants to merge 1 commit into
mainfrom
claude/fix-issue-8-spotify-prompt

Conversation

@shobhit99

Copy link
Copy Markdown
Owner

Summary

Closes #8 — the "Where is Spotify?" Finder picker no longer appears on app start when Spotify isn't installed.

Root cause

NowPlayingManager.fetchSpotifyViaAppleScript is called from refreshPreferredSource shortly after launch (see SuperIsland/Modules/NowPlaying/NowPlayingManager.swift:82) as part of normal source-detection polling. The script is structured like this:

tell application "System Events"
    if not (exists process "Spotify") then return "NOT_RUNNING"
end tell
tell application "Spotify"
    if player state is playing then
        ...

The first block runs via System Events and intends to bail out when Spotify isn't running. But AppleScript still resolves the second tell application "Spotify" block by bundle identifier at compile time — before any of the runtime exists process check fires. When Spotify.app isn't installed, macOS can't find the bundle and pops up the "Where is Spotify?" Finder picker.

Fix

  • New nonisolated private func isSpotifyInstalled() -> Bool that calls NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.spotify.client").
  • Early guard isSpotifyInstalled() else { return false } at the top of fetchSpotifyViaAppleScript.
  • Same guard in fetchSpotifyArtwork (which runs tell application "Spotify" to return artwork url ...).

When Spotify isn't installed we never hand the AppleScript to macOS, so no Finder picker appears.

The playback-control AppleScripts (play / pause / next / previous / seek) don't need the same guard — they are only reached once sourceName has already been set to "Spotify", which requires MediaRemote (or a successful fetchSpotifyViaAppleScript) to have reported Spotify as the active app, so Spotify must already be installed and running. togglePlayPause also bails via isApplicationRunning("Spotify").

Test plan

  • On a Mac without Spotify installed, launch SuperIsland cold — confirm the "Where is Spotify?" Finder picker no longer appears (the bug reproduction).
  • Confirm Now Playing still picks up music from Apple Music, Chrome, YouTube, etc. via the existing AppleScript and MediaRemote paths.
  • On a Mac with Spotify installed and playing, launch SuperIsland — confirm Spotify info (title, artist, album art) still appears in the compact and expanded views as before.
  • With Spotify installed, use play/pause/next/previous/seek controls — confirm they still work.
  • Install Spotify after SuperIsland is already running — note that a restart is required for the new install to be picked up (acceptable trade-off; the lookup is cached implicitly per-process).

On every launch, NowPlayingManager runs fetchSpotifyViaAppleScript as
part of its source-detection polling. That script contains a
`tell application "Spotify"` block, and even though the script guards
with `if not (exists process "Spotify") then return "NOT_RUNNING"`
inside a System Events tell, AppleScript still resolves the second
`tell application "Spotify"` by bundle identifier at compile time.
When Spotify.app isn't installed, macOS can't find the bundle and
pops up a "Where is Spotify?" Finder picker.

Gate fetchSpotifyViaAppleScript and fetchSpotifyArtwork on a new
isSpotifyInstalled() helper that checks
NSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.spotify.client").
When Spotify isn't installed we never hand the AppleScript to macOS,
so no Finder picker appears.

The playback-control AppleScripts (play/pause/next/prev/seek) don't
need the same guard — they are only reached once sourceName has
already been set to "Spotify", which requires Spotify to be running,
and they additionally bail via isApplicationRunning("Spotify") in
togglePlayPause.
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.

need a way to suppress "Where is Spotify" request on app start

2 participants