I have this script located in the attachments folder and have it run on server startup.
-- SlimServer control attachment
--
-- This script provides functions for easily controlling SlimDevices
-- SLIMP3 or Squeezebox from Indigo Execute AppleScript actions.
--
-- Author: Andrew Turner (software at highearthorbit dot com)
-- Changes: Paul Roomberg (paul at pasaro dot nl)
-- Nick Sosnicki - 30 Oct 2006 - v1.2
-- -tested on Indigo 2.0b8, SlimServer 6.5.0
-- -added error trapping to shell scripts
-- -set the curl connect timeout to 5 seconds
-- and the curl transaction time limit to
-- 10 seconds (these can be increased if needed)
-- - added option to ping server and Squeezebox to
-- see if they are there before sending commands
-- -added support for multiple Squeezeboxes through
-- a nick name/IP address definition; this requires
-- an extra parm for each command
-- -to support multiple Squeezebox status, multiple
-- status variables are used; these will be created
-- automatically if needed
-- -changed slim server display function to allow
-- dynamic control of the time to display
-- Matt Bendiksen - 1 Jan 2007 - v1.2.1
-- -general cleanup, bug fixes, and added to base
-- Indigo 2.0 install
--
-- __Attachment Functions__ Can be called from within Indigo Execute AppleScript actions,
-- or any _tell app "IndigoServer"_ block. If the squeezebox nickname is blank, the first
-- one defined in the map will be used.
--
-- SlimServerDisplay("Line 1", "Line 2", seconds to display, "Squeeze Nickname")
-- SlimServerVolume(volume, "Squeeze Nickname")
-- volume: 0-100
-- SlimServerPlaySong("Song Name", "Squeeze Nickname")
-- SlimServerSkipFwd("Squeeze Nickname")
-- SlimServerSkipRew("Squeeze Nickname")
-- SlimServerPower(On or Off, "Squeeze Nickname")
-- On or Off: 0 is off, 1 is on
-- SlimServerCommand("Command","Squeeze Nickname")
-- available commands: "play", "pause", "stop", "sleep"
--
-- Status variable are named "SlimStatus" and the Squeezebox's nick name
-- for example, "SlimStatusupBath1" and "SlimStatusupBath2"
property slimIP : "10.0.1.2" -- slimserver IP address
property slimPort : "9000" -- slimserver web port
-- Map of Squeezebox nicknames and their IP addresses. MAC addresses
-- can be used instead, but you must set pingSqueeze to false (the ping
-- test cannot be used with MAC addresses). Add a new pair for every
-- Squeezebox you want to control.
property squeezeMap : {¬
{"LivingRoom", "192.168.1.10"}, ¬
{"MasterBedroom", "192.168.1.11"} ¬
}
property pingSlim : true --if true, ping slimserver before commands
property pingSqueeze : true --if true, ping squeezebox before commands
property slimResponseText : ""
using terms from application "IndigoServer"
on SlimServerCommand(theCommand, squeezeNick)
SendToSlimServer(theCommand, 0, 0, 0, squeezeNick)
end SlimServerCommand
on SlimServerDisplay(displayString1, displayString2, displaySeconds, squeezeNick)
set lineOne to _searchReplaceText(" ", "%20", displayString1)
set lineTwo to _searchReplaceText(" ", "%20", displayString2)
SendToSlimServer("display", lineOne, lineTwo, displaySeconds, squeezeNick)
end SlimServerDisplay
on SlimServerVolume(volume, squeezeNick)
SendToSlimServer("mixer", "volume", volume, 0, squeezeNick)
end SlimServerVolume
on SlimServerPlaySong(songName, squeezeNick)
SendToSlimServer("playlist", "play", songName, 0, squeezeNick)
getSlimStatus(squeezeNick)
end SlimServerPlaySong
on SlimServerSkipFwd(squeezeNick)
SendToSlimServer("button", "jump_fwd", 1, 0, squeezeNick)
getSlimStatus(squeezeNick)
end SlimServerSkipFwd
on SlimServerSkipRew(squeezeNick)
SendToSlimServer("button", "jump_rew", 0, 0, squeezeNick)
getSlimStatus(squeezeNick)
end SlimServerSkipRew
on SlimServerPower(onOff, squeezeNick)
SendToSlimServer("power", onOff, 0, 0, squeezeNick)
getSlimStatus(squeezeNick)
end SlimServerPower
on SlimServerGetStatus(squeezeNick)
SendToSlimServer("status", 0, 0, 0, squeezeNick)
getSlimStatus(squeezeNick)
end SlimServerGetStatus
on SlimServerLog(logString)
tell application "IndigoServer"
log logString using type "SlimServer"
end tell
end SlimServerLog
on getSlimStatus(squeezeNick)
if squeezeNick is "" then
set squeezeNick to item 1 of item 1 of squeezeMap
end if
tell application "IndigoServer"
-- if a status variable pair does not exisit for this Squeeze's nick name, create it
set statusVar1 to "SlimStatus" & squeezeNick & "1"
set statusVar2 to "SlimStatus" & squeezeNick & "2"
if not (variable statusVar1 exists) then
make new variable with properties {name:statusVar1, value:first paragraph of slimResponseText}
else
set value of variable statusVar1 to the first paragraph of slimResponseText
end if
if not (variable statusVar2 exists) then
make new variable with properties {name:statusVar2, value:last paragraph of slimResponseText}
else
set value of variable statusVar2 to the last paragraph of slimResponseText
end if
end tell
end getSlimStatus
on SendToSlimServer(p0, p1, p2, p3, squeezeNick)
--lookup IP for squeeze box nickname if provided, else use first entry
if squeezeNick is "" then
set squeezeIP to item 2 of item 1 of squeezeMap
else
set squeezeIP to ""
repeat with mapEntry in squeezeMap
if item 1 of mapEntry is squeezeNick then
set squeezeIP to item 2 of mapEntry
exit repeat
end if
end repeat
end if
if squeezeIP is "" then
SlimServerLog("Squeezebox nickname " & squeezeNick & " or IP address is not defined")
return
end if
set pingSucess to true
if pingSlim then --try to ping slimserver
if not PingAddress(slimIP) then
set pingSucess to false
set slimResponseText to "SlimServer at " & slimIP & " not reachable"
SlimServerLog("SlimServer at " & slimIP & " not reachable")
end if
end if
if pingSqueeze then --try to ping squeezebox
if not PingAddress(squeezeIP) then
set pingSucess to false
set slimResponseText to "Squeezebox at " & squeezeIP & " not reachable"
SlimServerLog("Squeezebox at " & squeezeIP & " not reachable")
end if
end if
if pingSucess then
set h to "http://" & slimIP & ":" & slimPort & "/status.txt"
set d to h & "?p0=" & p0
if p1 is not equal to 0 then set d to d & "&p1=" & p1
if p2 is not equal to 0 then set d to d & "&p2=" & p2
if p3 is not equal to 0 then set d to d & "&p3=" & p3
set d to d & "&player=" & squeezeIP
try
set slimResponseText to doShellScript("curl --connect-timeout 5 --max-time 10 --get -d --url \"" & d & "\" ")
on error errStatement number errNum
set slimResponseText to "Connection error (CURL): " & errNum
SlimServerLog("Connection error (CURL) with SlimServer at " & slimIP & "; error number: " & errNum)
end try
end if
end SendToSlimServer
end using terms from
-- Pings given address and returns true if there were no errors, false if there were errors
on PingAddress(IPAddress)
set errTest to true
try
set ping_result to doShellScript("ping -o -q -n -t 3 " & IPAddress)
on error errStatement number errNum
set errTest to false
end try
return errTest
end PingAddress
-- Glue for shell scripts to ensure correct environmental vars are used
on doShellScript(scriptStr)
tell application "Finder" to set returnVal to do shell script scriptStr
return returnVal
end doShellScript
(*
_searchReplaceText(searchTerm, replaceTerm, theText)
Replaces a string found in a text by another string.
This handle supports lists of search/replace terms.
Parameters:
searchTerm: the text to search for
replaceTerm: the text to use as replacement
theText: the text to search/replace
Examples:
_searchReplaceText("foo", "bar", "You are a foo") --> "You are a bar"
_searchReplaceText({"foo", " a "}, {"bar", " one "}, "You are a foo") --> "You are one bar"
*)
to _searchReplaceText(searchTerm, replaceTerm, theText)
set searchTerm to searchTerm as list
set replaceTerm to replaceTerm as list
set theText to theText as text
set oldTID to AppleScript's text item delimiters
repeat with i from 1 to count searchTerm
set AppleScript's text item delimiters to searchTerm's item i
set theText to theText's text items
set AppleScript's text item delimiters to replaceTerm's item i
set theText to theText as text
end repeat
set AppleScript's text item delimiters to oldTID
return theText
end _searchReplaceText
I then execute this as an action to turn the radio off: SlimServerPower("0", "Squeeze Nickname")
I've tried to read and understand how this all works but can't seem to get it to work.
I see in the Squeezebox server info the server is 10.0.1.2 but the radio itself has a different address, 10.0.1.23
I assume the server info is correct to enter into the script, not the radio itself?
Any help greatly appreciated!
Carl