There is an iMac in our lab at university, running Mac OS X 10.7 Lion.

It is never used, so we have taken to using it to play music, as we can SSH to it, and it does not require any permissions to play music (using afplay).

Is there any way to stream radio, or any other music stream from the command line?

  • Enable screen sharing, then you can connect using VLC and do what ever you want with itunes and youtube. Commented Jun 6, 2020 at 11:24

4 Answers 4


While not (strictly speaking) playing from the command line, you could use a set of AppleScripts (or AppleScript calls) wrapped in shell scripts to control a GUI player or website. In the likely case that the player or site doesn't directly support AppleScriptability, you can use AppleScript GUI scripting to control the mouse and keyboard.

If you're looking at a "normal" streaming radio station (i.e, one that has a downloadable file that specifies the stream), you can put that in iTunes and use its (relatively excellent) AppleScript dictionary to remotely control it.

With either option, if you want to get fancy, you can use remote scripting to send Apple Events from an arbitrary source machine to control your radio-iMac.

  • Are you able to do this if no one is physically logged in on the machine? Commented Aug 3, 2012 at 1:24
  • Maybe. Probably not. I did some poking around and I was able to get Pandora to launch with no GUI user logged in (only after sudo'ing to the root user), but the window never showed up and the music never played. (It also launched the Adobe AIR updater, so that may have been a/the problem. I also didn't wait very long.)
    – Cajunluke
    Commented Aug 3, 2012 at 1:52
  • I wasn't actually aware that you could stream radio through iTunes, thanks. I ended up just logging into the machine, opening a radio stream in iTunes and locking the screen. Commented Aug 16, 2012 at 21:14

You can run VLC to play a stream from the command line:

/Applications/VLC.app/Contents/MacOS/VLC <address>

For example this (address from here) will play BBC Radio 3:

/Applications/VLC.app/Contents/MacOS/VLC http://a.files.bbci.co.uk/media/live/manifesto/audio/simulcast/hls/uk/sbr_high/ak/bbc_radio_three.m3u8

To stop playing, press or send Ctrl+C.

For more information on the command line interface see here and the pages linked from it.



Use the relay function.


I was interested to know the answer to this one myself, so I googled it. Here you go :-)

I use MPlayer under linux, this is a mac port. I typically use cron to schedule the job, mplayer dumps the stream to a tmp wav file and then I use lame to encode it to mp3. If it is already in mp3 format you may be able to configure mplayer to dump directly to mp3.

Here's my script with the url and meta-data cleared:

TMP1=`mktemp -p /var/tmp stream.XXXXXX`
OUTFILE=/var/music/mp3/streams/stream_`date +%b_%d_%Y`.mp3

mplayer -quiet -playlist http://XXX/playlist.pls -ao pcm:fast:file=$TMP1 -vc dummy -vo null -endpos 01:05:00
lame $TMP1 $OUTFILE --tt `date +%D` --ta "Artist" --tg "Genre" --tl "Title" --id3v1-only --nohist --preset standard

rm -f $TMP1
  • 1
    Thanks for the link, not quite what I was looking for. I want to play the music through the speakers, not record it to file. I'll try and see if I can get mplayer running, but I'm not sure, the latest version I can find is from 2005... Commented Aug 3, 2012 at 0:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .