mcthomas / Apple-Music-CLI-Player

A simple command-line Apple Music controller script which includes a "Now Playing" widget function, a playback function, and a list-out function for your Mac's Music.app library, written in sh.
MIT License
107 stars 10 forks source link

bash: line 0: read: .5: invalid timeout specification; np:read:130: bad option: -N #1

Closed albert-ying closed 1 year ago

albert-ying commented 1 year ago

Nice work! When I run the zsh am.sh np, I got these two lines of error message keep blinking. And the keyboard shortcut seems not working. Any idea how to fix it? Thank you!

mcthomas commented 1 year ago

Hi @albert-ying ,

Sorry about that! Seems to be zsh specific, I don't see this artifact when the script is run with bash. Read from stdin works differently in bash and zsh. I just added a call to bash for that line (bash isn't going anywhere anytime soon, even though zsh is default on macOS).

Please pull down and let me know if that resolved the issue.

albert-ying commented 1 year ago

Thanks for the quick reply!

Now it looks like this

bash: line 0: read: .5: invalid timeout specification
/usr/bin/read: line 4: read: -N: invalid option
read: usage: read [-ers] [-u fd] [-t timeout] [-p prompt] [-a array] [-n nchars] [-d delim] [name ...]

Also, if seems that I can't run it use bash


❯ bash am.sh np
am.sh: line 26: arr: bad array subscript
am.sh: line 43: arr: bad array subscript
am.sh: line 87: (curr * 100) / end / 10 : division by 0 (error token is "/ 10 ")

❯ bash am.sh list -a
pr: illegal option -- T
usage: pr [+page] [-col] [-adFfmprt] [-e[ch][gap]] [-h header]
          [-i[ch][gap]] [-l line] [-n[ch][width]] [-o offset]
          [-L locale] [-s[ch]] [-w width] [-] [file ...]
``
mcthomas commented 1 year ago

As I have indicated in the readme, for np, you need to have a song playing or paused. That's usually the error you'll otherwise see because there is no song duration for it to parse and operate on. Sorry for that inconvenience.

For the other error, are you using Darwin's bash or a bash package from elsewhere? Check with bash --version. It could also be related to the fact that I have an sh shebang instead of a bash shebang on top of the script. I just updated this in case it is the culprit for your system. Let me know what happens after you pull down again.

albert-ying commented 1 year ago

Hi Thomas, I pull the lastest version.

See attached screen recording

https://share.cleanshot.com/jghCmg

My bash is the darwin

❯ bash --version
GNU bash, version 3.2.57(1)-release (arm64-apple-darwin22)
Copyright (C) 2007 Free Software Foundation, Inc.
mcthomas commented 1 year ago

I think we might've found the problem. My bash is

GNU bash, version 5.2.2(1)-release (x86_64-apple-darwin21.6.0)
Copyright (C) 2022 Free Software Foundation, Inc.

It is I who has a newer Darwin package. And the original package, the default that you have, must have issues with my expressions' syntax and with cut as they appear in np(), as well as with the pr option T for list(). So it seems like this script shouldn't be listed as being compatible with the OTB bash. Sorry for any confusion.

The easy solution would be to call it with zsh as you were originally. I changed the shebang back to zsh and updated the option to -k on read. Please pull down again and try with zsh instead of bash.

albert-ying commented 1 year ago

Thanks, now I can run np with zsh with no error! It still blinks, though, I guess that is not avoidable?

p.s. works great with cava ;)

image
mcthomas commented 1 year ago

No problem, thank you so much for pointing this out to me. I can see the spacing is way off with the text. I realized this is because, iterm2 supports viu in full resolution. I just added the -b flag to forced blocks. Feel free to pull if you want that fixed, or you can try to keep the resolution and resolve the spacing yourself.

As for the blinking, I don't see this occurring in terminal.app. I will look into it.

albert-ying commented 1 year ago

Thanks! It stops blinking after I pull the latest commit

One question -- is it possible to play from the station using this tool?

mcthomas commented 1 year ago

I am glad, though I think blinking will persist for some of the heavier terminal emulators, unfortunately, and there isn't much I can do about it.

I don't believe you can use AppleScript to begin playback from a Radio Station, unfortunately, because Radio Stations are not defined in Music.sdef (from Script Editor.app's Dictionary). Furthermore, there's really no way to save those to your library.