View Full Version : Sending tracks from iTunes to Squeezebox (mac only, uses applescript)

2012-12-10, 14:15
I have long wanted to play tracks directly from iTunes to squeezebox, using the command line interface. (The reason I want to do this is that I can actually find my music in iTunes, because it has an adequate search facility.)

I have an applescript to do this, based on previous applescripts by A. Schroeder and B. Mohr; for these previous scripts see http://forums.slimdevices.com/showth..._from_-iTunes/.

To save the script, paste the code into the applescript editor and then save as a script in the location of your choice. You can run it from the applescript editor or from iTunes, as indicated below.

**To use, select some tracks in iTunes, and then run the script. You will be asked whether to play the tracks or append the list of tracks to the current LMS playlist.

**The script can be placed in ~/Library/iTunes/Scripts and run from the script menu in iTunes.

**The script allows paths with any unicode characters.

**You can specify the player to be used, using the player id, which is the MAC hardware address of the player. If you don't specify a player, the first player on the LMS list of players will be used.

The script starts here:

-- SlimPlay
-- by F. Goodman, Dec. 2012
-- by Alex Schroeder, kensanata@gmail.com
-- March 2008
-- by Brad Mohr, bmohr (AT) seanet (DOT) com
-- 22 January 2003
-- This script is absolutely free and may be used by anyone for any purpose.

-- Known Limitations:
-- Currently only supports a single Squeezebox.
-- Very little error checking

-- edit these properties to match your setup.
property squeezecenter_host : "localhost" -- URL or IP address of the SlimServer
property squeezecenter_port : "9090" -- server port number for the command line interface, default is 9090
property player_id : " " -- MAC address of desired player; leave blank to use default or only player
--property player_id : "00:04:20:10:13:3a " -- TRANSPORTER
--property player_id : "00:04:20:06:ac:e0 " -- SLIMP3

tell application "iTunes"
set these_tracks to the selection of browser window 1
if these_tracks is {} then error "No tracks are selected in the front window."

set should_play to false

display dialog "What would you like to do with these tracks?" buttons {"Play", "Append", "Cancel"} default button 2
if the button returned of the result is not "Cancel" then
if the button returned of the result is "Play" then set should_play to true

set is_first_file to true

repeat with a_track in these_tracks
set carbon_filepath to the location of a_track
set track_title to the name of a_track

tell application "Finder" to set filepath to POSIX path of carbon_filepath
set escaped_path to encode_URL(filepath) of me
if should_play then
if is_first_file then
playlist_play_track(escaped_path) of me
set is_first_file to false
playlist_append_track(escaped_path) of me
end if
playlist_append_track(escaped_path) of me
end if
end repeat

if should_play then
begin_playing() of me
end if
end if
end tell

-- The following code using python is taken from
--AppleScript: The Comprehensive Guide to Scripting and Automation on Mac OS X, by Hanaan Rosenthal

on encode_URL(txt)
set python_script to ¬
"import sys, urllib; print urllib.quote(sys.argv[1])"
set python_script to "python -c " & ¬
quoted form of python_script & " " & ¬
quoted form of txt
return do shell script python_script
end encode_URL

-- append the new track to the playlist
on playlist_append_track(escapedTrackPath)
send_command("playlist add " & escapedTrackPath)
end playlist_append_track

-- replace the existing playlist with the new track
on playlist_play_track(escapedTrackPath)
send_command("playlist play " & escapedTrackPath)
end playlist_play_track

-- tell the default (or only) server to begin playing
on begin_playing()
end begin_playing

on send_command(command)
tell application "Finder"
set shell_command to "echo '" & player_id & command & "\\nexit' | /usr/bin/nc " & squeezecenter_host & " " & squeezecenter_port & "; exit 0"
-- display dialog shell_command buttons {"Ok"}
set result to do shell script shell_command
-- display dialog result buttons {"Ok"}
end tell
end send_command

2018-05-26, 23:40
Also old thread. Since a friend (Apple adept) is looking into multi zone music it's got my attention.
Is this script still being active developed and does it now work with multiple SB?

2018-05-27, 06:52
Also old thread. Since a friend (Apple adept) is looking into multi zone music it's got my attention.
Is this script still being active developed and does it now work with multiple SB?

I haven't used it in a long time and I don't know if it works anymore. For me it is no longer needed as the LMS software has an adequate search facility.

2018-05-27, 14:36
Ok, thnx

2018-05-28, 11:28
Ok, thnx
if you use shairtunes, you will be able to turn any SB into an AirPlay compatible player, so you’ll be able to play tracks from iTunes

2018-05-28, 12:31
Nice suggestion!