I want to use iTunes to render a http mp3 stream on MacOSX. I understand the best way to remote control iTunes programmatically is AppleScript and I already can start iTunes, but:
- what is the correct syntax to open a stream from a URL?
- is it possible to keep iTunes invisible / hidden when running it via apple script? It always opens the GUI..
Sending iTunes a command while it’s not running will cause it to start up and display its default GUI; there’s no easy way around that.
But if you want to force iTunes to hide, rather than keep it hidden if it wasn’t already visible, you can do that:
Or, if you only want to hide iTunes if your script launched it, you can do something like this:
Of course there are some edge cases it doesn’t handle (e.g., if iTunes was running, but the browser window was minimized, you will cause it to unminimize, and won’t re-minimize it); look through the iTunes and System Events dictionaries and experiment with each edge case you care about. Also, there’s a small race condition (if the user, or another script, happens to launch it after your check…), but there’s not much you can do about that.
You don’t actually need the “play” except in certain uncommon cases (e.g., iTunes is already paused on a stream), but it doesn’t hurt.
Finally, by default, this will add “your_url_here” to a playlist called “Internet Songs” each time you run it, even if it’s already there, creating the playlist if necessary. Hopefully you don’t mind that; if you do, there are more tricks to learn.