Play Otvoreni Radio – version 2.2
Yet again another version of Play Otvoreni Radio. I changed some bulky, redundant steps and fixed a little “bug”: after the playback starts, the Otvoreni Radio playlist wasn’t always selected. So, if I presses play on the remote after I paused the radio, iTunes started to play the last selected playlist – which mostly wasn’t the right one.
Downloads:
Play Otvoreni Radio Application V2.2![]()
Play Otvoreni Radio Script V2.2 (PDF version)
Play Otvoreni Radio Script V2.2 (.scpt version)
What is this script doing?
1. Variables
First it sets a series of variables. In my case I used all known URLs of Otvoreni Radio. Additional I created a variable with the playlist name (which is frequently used) and made a list which includes all the URLs.
-
set myPlaylistName to "Otvoreni Radio"
-
-
global myUrl01 – set the URl for the 1st track
-
set myUrl01 to "http://tv29.stream-music.net:8200/"
-
-
global myUrl02 – set the URl for the 2nd track
-
set myUrl02 to "http://tv27.stream-music.net:8100/"
-
-
global myUrl03 – set the URl for the 3rd track
-
set myUrl03 to "http://82.193.201.234:8001/"
-
-
global myUrl04 – set the URl for the 4th track
-
set myUrl04 to "http://213.147.125.75:8003/"
-
-
global myVolume – set your desired volume (default is 50%)
-
set myVolume to 50
-
-
global enableMyEQ – decide if the EQ will be enabled
-
set enableMyEQ to true
-
-
global myURLs
-
set listOfUrls to {myUrl01, myUrl02, myUrl03, myUrl04} –creates a list of URLS
2. Functions
Here are functions which will execute our desired operation.
startPlayBackOfPlayList()
This simply starts the playback of the mentioned playlist. It also sets the EQ and the volume. And, of course, it tells iTunes to focus on the playlist.
-
try
-
tell application "iTunes"
-
set sound volume to myVolume
-
set EQ enabled to enableMyEQ
-
play user playlist myPlaylistName –this plays the first track of playlist
-
set view of front browser window to user playlist myPlaylistName –sets focus
-
end tell
-
on error
-
errorCouldNotPlay() – display error and offer a retry
-
end try
-
end startPlayBackOfPlayList
checkIfPlayListExists()
If the playlist already exists, the script should skip the playlist creation. From the second start on, it will proceed much faster.
-
set checkList to myPlaylistName
-
tell application "iTunes"
-
exists user playlist checkList
-
end tell
-
end checkIfPlayListExists
createMyPlaylist()
Pretty obvious, this created the playlist. But it also calls: addToMyPlayList().
-
try
-
tell application "iTunes"
-
set newPlayList to make new user playlist with properties {name:myPlaylistName}
-
end tell
-
addToMyPlayList()
-
on error
-
errorCouldNotCreatePlayList()
-
end try
-
end createMyPlaylist
addToMyPlayList()
Here we are adding the above set URLs to the newly created playlist. After this is done, it will start playing the list.
-
tell application "iTunes"
-
try
-
repeat with i from 1 to number of items in listOfUrls
-
set myUrl to item i of listOfUrls
-
tell application "iTunes"
-
set my_playlist to myPlaylistName – set the target playlist
-
open location myUrl – open an URL from the list
-
stop – but don't play right away
-
set new_stream to (some URL track of library playlist 1 whose address is myUrl)
-
duplicate new_stream to playlist my_playlist –copy it into the playlist
-
set view of front browser window to playlist my_playlist
-
end tell
-
end repeat
-
on error
-
errorCouldNotAddToPlayList()
-
end try
-
-
set sound volume to myVolume
-
set EQ enabled to enableMyEQ
-
try
-
tell playlist my_playlist
-
play track (get name of new_stream)
-
set view of front browser window to user playlist myPlaylistName –sets focus
-
end tell
-
on error
-
–display dialog "DEBUG: addToMyPlayList – could not play" with icon 0
-
errorCouldNotPlay()
-
end try
-
end tell
-
-
end addToMyPlayList
hideItunes()
After everything is done, this will minimize the iTunes window.
-
tell application "Finder"
-
set the visible of every process whose name is "iTunes" to false
-
end tell
-
end hideItunes
3. Errors
Sometimes an operation isn’t successful. To catch these problems, the script has some error handlers
errorCouldNotPlay()
If the playback couldn’t be started, this will ask the user how it should proceed. If the decision is: try again, it’ll wait for a second before the next attempt. If this one also fails, it will close for good.
-
set answer to the button returned of (display dialog "Couldn't start playback" buttons {"Try again", "Cancel"} default button 1)
-
if answer = "Try again" then
-
delay 1 – wait for one second
-
startPlayBackOfPlayList()
-
else
-
error number -128 – end script
-
end if
-
end errorCouldNotPlay
errorCouldNotAddToPlayList()
If addToMyPlayList() caused an error, this one will try it again.
-
set answer to the button returned of (display dialog "Couldn't add URLs to playlist" buttons {"Try again", "Cancel"} default button 1)
-
if answer = "Try again" then
-
delay 1 – wait for one second
-
addToMyPlayList()
-
else
-
error number -128 – end script
-
end if
-
end errorCouldNotAddToPlayList
errorCouldNotCreatePlayList()
And the same thing for createMyPlaylist().
-
set answer to the button returned of (display dialog "Couldn't create playlist" buttons {"Try again", "Cancel"} default button 1)
-
if answer = "Try again" then
-
delay 1 – wait for one second
-
createMyPlaylist()
-
else
-
error number -128 – end script
-
end if
-
end errorCouldNotCreatePlayList
4. Calls
The only thing left to do, is to call all our functions in the right order.
-
if checkIfPlayListExists() = false then
-
createMyPlaylist() – if your playlist doesn't exist, create it, add URLs and start playback
-
else
-
startPlayBackOfPlayList() – if your playlist exists, start playback
-
end if
-
on error
-
startPlayBackOfPlayList() – if your playlist exists, start playback
-
end try
-
-
hideItunes()
This should have been the final version – but maybe I’ll add a timer into it, so it will start playing automatically in the morning…

















