Skip Spotify AppleScript when Spotify isn't installed (fix #8)#23
Open
shobhit99 wants to merge 1 commit into
Open
Skip Spotify AppleScript when Spotify isn't installed (fix #8)#23shobhit99 wants to merge 1 commit into
shobhit99 wants to merge 1 commit into
Conversation
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.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #8 — the "Where is Spotify?" Finder picker no longer appears on app start when Spotify isn't installed.
Root cause
NowPlayingManager.fetchSpotifyViaAppleScriptis called fromrefreshPreferredSourceshortly after launch (seeSuperIsland/Modules/NowPlaying/NowPlayingManager.swift:82) as part of normal source-detection polling. The script is structured like this:The first block runs via
System Eventsand intends to bail out when Spotify isn't running. But AppleScript still resolves the secondtell application "Spotify"block by bundle identifier at compile time — before any of the runtimeexists processcheck fires. When Spotify.app isn't installed, macOS can't find the bundle and pops up the "Where is Spotify?" Finder picker.Fix
nonisolated private func isSpotifyInstalled() -> Boolthat callsNSWorkspace.shared.urlForApplication(withBundleIdentifier: "com.spotify.client").guard isSpotifyInstalled() else { return false }at the top offetchSpotifyViaAppleScript.fetchSpotifyArtwork(which runstell 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
sourceNamehas already been set to"Spotify", which requires MediaRemote (or a successfulfetchSpotifyViaAppleScript) to have reported Spotify as the active app, so Spotify must already be installed and running.togglePlayPausealso bails viaisApplicationRunning("Spotify").Test plan