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, [email protected]
-- 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
else
playlist_append_track(escaped_path) of me
end if
else
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()
send_command("play")
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


------------------------------------------------------------------------
fredgoodman's Profile: http://forums.slimdevices.com/member.php?userid=7616
View this thread: http://forums.slimdevices.com/showthread.php?t=97523

_______________________________________________
discuss mailing list
[email protected]
http://lists.slimdevices.com/mailman/listinfo/discuss

Reply via email to