Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exit with 1 if Spotify isn't actually started #117

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

redradrat
Copy link

@redradrat redradrat commented May 16, 2019

Starting Spotify - if it's not actually started - is magic, and should only be done explicitly.

Thus, this PR changes starting Spotify.app via osascript to printing the according error and exiting with 1.

Adresses #114

@hnarayanan
Copy link
Owner

Hmm, I am not sure I agree.

@redradrat
Copy link
Author

redradrat commented May 16, 2019

I'd say spotify start would be in line with the current approach, as there is already spotify quit.
Or something along the lines of spotify play --startifnotstarted?

@hnarayanan
Copy link
Owner

Again, I am not sure I agree.

I do agree with your narrow case in the issue where spotify status starts it up when it should probably just tell you it is not started. But I want to be able to type spotify play and just have it do the right thing and not have me say something like --really-start-if-not-already-started

@redradrat
Copy link
Author

Your argument is understandable. What would you think should be the right behaviour for spotify quit?

  1. Start Spotify, Stop, Quit Spotify
  2. Exit 0

@hnarayanan
Copy link
Owner

Exit 0.

So we need to figure out how to do this in a way that is right for each command, and I am guessing spotify play (and its variants) is the only case where we want it to magic start.

@redradrat
Copy link
Author

I can agree to that :) I'll see if I can whip something up on the weekend.

@hnarayanan
Copy link
Owner

Thank you 👍

@Amar1729
Copy link
Contributor

Would a good compromise be to include something like an AUTOSTART variable in the config file? Something like this:

# original line: https://github.com/hnarayanan/shpotify/blob/c93a1e939a7f3260fefe8ed2537733c89d88caee/spotify#L29
USER_CONFIG_DEFAULTS="CLIENT_ID=\"\"\nCLIENT_SECRET=\"\"\nSPOTIFY_AUTOSTART=1";

and

# https://github.com/hnarayanan/shpotify/blob/c93a1e939a7f3260fefe8ed2537733c89d88caee/spotify#L153-L156
    if [ $(osascript -e 'application "Spotify" is running') = "false" ]; then
        if [ "$SPOTIFY_AUTOSTART" -eq 0 ]; then
            echo "Spotify not starting automatically. Exiting."
            exit 1
        fi

        osascript -e 'tell application "Spotify" to activate' || exit 1
        sleep 2
    fi

Note the default is to autostart spotify (author's preference), but in this way a user can choose to explicitly have to open Spotify.

@Peter-Schorn
Copy link

Peter-Schorn commented Dec 26, 2019

From what I can tell, the following lines are unnecessary:

if [ $(osascript -e 'application "Spotify" is running') = "false" ]; then
        osascript -e 'tell application "Spotify" to activate' || exit 1
        sleep 2
fi

Spotify does NOT need to be running in order for it to respond to apple script requests; it will launch automatically and respond to the apple script. I suggest that you remove this section. Also, with this section included, if Spotify is not running before I enter a command, when I run a command it will launch and become the frontmost application. I don't like having the Spotify window launch and filling up my screen when I can just control it from the command line. After commenting out the above section, when I run a command, Spotify launches, but stays hidden. If, for some reason, I'm wrong, at the very least Spotify can be launched hidden via the following terminal command: open -a Spotify -j

Edit: some more info about open -a Spotify -j
-a specifies that the following argument is the name of an application to open
-j launches the application hidden
run man open for more information

@hnarayanan
Copy link
Owner

Please look up git blame and when this code was added/changed. I don't have strong opinions on this and either (a) I did something wrong (most likely) or (b) someone added this code because their pet case didn't work out.

@Amar1729
Copy link
Contributor

I'd forgotten but apparently that was me to solve #73

@Peter-Schorn i added that line at some point to address the (admittedly odd) edge case of a weird error message if Spotify.app wasn't installed at all.

I think your open solution works much better though.

@Peter-Schorn
Copy link

Peter-Schorn commented Jan 2, 2020

I just created a python script that allows you to play Spotify songs directly from spotlight search on macOS! Check it out here

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.

4 participants