So here's a "small" tutorial for SLIMP3 integration in Indigo.
This will probably work for the SqueezeBox as well, but as I don't have one of these, I can't tell for sure. However, donations are welcome...
The end result wil be a control page like this:
What do you need?
- Indigo 2.0
- SlimServer 6.x
- A SLIMP3 (or SqueezeBox) player
- The SlimServer script
- A couple of action groups, variables and a time/date action
- A control page and some extra buttons
Indigo 2.0, SlimServer 6.x and the SLIMP3 need to be up and running and fully functional. Indigo and the SlimServer do not need to run on the same machine. As long as Indigo can connect to the IP adress of the computer where the SlimServer is running.
Installing the SlimServer script
The SLIMP3 will be controled by Indigo via AppleScript. To do this, you will need the SlimServer script posted below. This script is based upon the original SlimServer script posted here by Andrew Turner.
- Code: Select all
--SlimServer control attachment
--
-- This script provides functions for easily controlling
-- a SlimDevices SLIMP3 or Squeezebox from IndigoActions
--
-- Author: Andrew Turner (software at highearthorbit dot com)
-- Changes: Paul Roomberg (paul at pasaro dot nl)
--
-- Examples:
-- SlimServerCommand("play")
-- SlimServerDisplay("Security", "Security Alarm Set")
--
-- Available commands: play, pause, stop, sleep
property defaultHost : "<IP>"
property defaultPort : "9000"
(* How long to display text *)
property defaultSeconds : "10"
property responseText : ""
using terms from application "IndigoServer"
on SlimServerCommand(theCommand)
SendToSlimServer(theCommand, 0, 0, 0)
end SlimServerCommand
on SlimServerDisplay(displayString1, displayString2)
set lineOne to searchReplaceText(" ", "%20", displayString1)
set lineTwo to searchReplaceText(" ", "%20", displayString2)
SendToSlimServer("display", lineOne, lineTwo, defaultSeconds)
end SlimServerDisplay
on SlimServerVolume(volume)
SendToSlimServer("mixer", "volume", volume, 0)
end SlimServerVolume
on SlimServerPlaySong(songName)
SendToSlimServer("playlist", "play", songName, 0)
getSlimStatus()
end SlimServerPlaySong
on SlimServerSkipFwd()
SendToSlimServer("button", "jump_fwd", 1, 0)
getSlimStatus()
end SlimServerSkipFwd
on SlimServerSkipRew()
SendToSlimServer("button", "jump_rew", 0, 0)
getSlimStatus()
end SlimServerSkipRew
on SlimServerPower(onOff)
SendToSlimServer("power", onOff, 0, 0)
getSlimStatus()
end SlimServerPower
on SlimServerGetStatus()
SendToSlimServer("status", 0, 0, 0)
getSlimStatus()
end SlimServerGetStatus
on getSlimStatus()
set value of variable "SlimStatus1" to the first paragraph of responseText
set value of variable "SlimStatus2" to the last paragraph of responseText
end getSlimStatus
end using terms from
on SendToSlimServer(p0, p1, p2, p3)
set h to "http://" & defaultHost & ":" & defaultPort & "/status.txt"
set d to h & "?p0=" & p0
if p1 is not equal to 0 then
set d to d & "&p1=" & p1
end if
if p2 is not equal to 0 then
set d to d & "&p2=" & p2
end if
if p3 is not equal to 0 then
set d to d & "&p3=" & p3
end if
set responseText to do shell script "curl --get -d --url \"" & d & "\" "
--alert("Server says: " & responseText)
end SendToSlimServer
(*
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
Open the ScriptEditor. You can find it in the AppleScript folder inside your Programs folder.
Copy the code above and paste it into the empty script window.
Change the property defaultHost so it containts the IP address of the computer where your SlimServer is running. If you changed the default port to something else than 9000, change that property also.
Save the script as "SlimServer.scpt" into the Indigo Scripts folder. It's in Library>Application Support>Perceptive Automation>Indigo 2>Scripts>Attachments on the Mac where the Indigo Server is running.
Start an Indigo Client and select Reload Attachments from the Scripts menu.
You'll see a list of scripts being loaded in the log window. Your SlimServer script should appear in this list.
At this point, everything is in place for the integration of the SLIMP3 with Indigo.
So now it's time to let Indigo control the SLIMP3.
Create actions groups, variables and the time/date action
For the control page to work, Indigo must be able to:
- Start playing a song on the SLIMP3
- Forward to a new song
- Rewind to a previous song
- Change the volume
- Power Off the SLIMP3
For each of these actions, an action group will be made.
Start playing a song on the SLIMP3
Create a new Action Group and name it "SlimServer On".
Give it a type of AppleScript and enter the following embedded code:
- Code: Select all
SlimServerCommand("play")
SlimServerVolume(value of variable "SlimVolume")
set value of variable "SlimPower" to "on"
Power Off the SLIMP3
Create a new Action Group and name it "SlimServer Off".
Give it a type of AppleScript and enter the following embedded code:
- Code: Select all
SlimServerPower(0)
set value of variable "SlimPower" to "off"
Skip to the previous song
Create a new Action Group and name it "SlimServer Rew".
Give it a type of AppleScript and enter the following embedded code:
- Code: Select all
SlimServerSkipRew()
Skip to the next song
Create a new Action Group and name it "SlimServer Fwd".
Give it a type of AppleScript and enter the following embedded code:
- Code: Select all
SlimServerSkipFwd()
Raise the volume
Create a new Action Group and name it "SlimServer VolumeUp".
Give it a type of AppleScript and enter the following embedded code:
- Code: Select all
set newVol to ((value of variable "SlimVolume") + 10)
if newVol > 100 then set newVol to 100
SlimServerVolume(newVol)
set value of variable "SlimVolume" to newVol
Lower the volume
Create a new Action Group and name it "SlimServer VolumeDown".
Give it a type of AppleScript and enter the following embedded code:
- Code: Select all
set newVol to ((value of variable "SlimVolume") - 10)
if newVol < 0 then set newVol to 0
SlimServerVolume(newVol)
set value of variable "SlimVolume" to newVol
Get the status as displayed on the SLIMP3
Create a new Action Group and name it "SlimServer Status".
Give it a type of AppleScript and enter the following embedded code:
- Code: Select all
SlimServerGetStatus()
The next step is to create the four variables which are used in the code above.
The first one is named "SlimVolume". Give it a value of 100.
The second is named "SlimPower". Give it a value of "off".
Then define "SlimStatus1" and "SlimStatus2" and leave their values empty.
Now it's time to define the time/date action. This will retrieve the SLIMP3 status every minute so it can be displayed in the control page.
Define a new Time/Date Action and name it "SlimServer Status".
Enter Every 0 hours 1,00 minutes in the Time section.
Enter Every 1 days in the Date section.
Go to the Actions tab and change the Type to Execute AppleScript.
Enter the following embedded code:
- Code: Select all
if value of variable "SlimPower" = "on" then
SlimServerGetStatus()
else
set value of variable "SlimStatus1" to ""
set value of variable "SlimStatus2" to ""
end if
From now on, everytime you turn on your SLIMP3 using Indigo, the contents on the display will be available in the variables SlimStatus1 and SlimStatus2. If you want a more up-to-date reading of the display, lower the interval. But keep in mind that this might affect the way Indigo responds to other events.
And now it's time to draw the picture!
Define the control page
To define the control page as shown at the beginning of this tutorial, you need three extra buttons.
Ctrl-Click on these buttons and save them to the folder where Indigo stores it's images.
This is Library>Application Support>Perceptive Automation>Indigo 2>IndigoWebServer>images>controls>static.
Define a new Control Page and name it "SLIMP3".
Add a new item to the page and set Display to "Static Image / Caption".
Choose "iTunesFace.png" for the image and clear the Caption field.
Set the Click Action to "None".
Add another new item the page. Keep the Display to "Static Image / Caption".
Choose "iTunesPlay_small.png" for the image and position it on the iTunes Face.
Clear the Caption field.
Set the Click Action to "Execute Action Group" and select the Action Group "SlimServer On" in the pop-up window.
Repeat this step to add the following images to the iTunes Face and connect them to their Action Groups:
Power_small.png => SlimServer Off
iTunesRW_small.png => SlimServer Rew
iTunesFF_small.png => SlimServer Fwd
VolumeDownLeft.png => SlimServer VolumeDown
VolumeUpRight.png => SlimServer VolumeUp
To get some info on the "LCD display", we need to display the variables SlimStatus1 and SlimStatus2.
Add a new item to the page and set Display to "Variable Value".
Choose SlimStatus1 for the variable to display.
Display as text with centered alignment, font Verdana, size 10.
Change the color to gray 50%.
Clear the caption field and set the Click Action to "None".
Drag this field on top of the iTunesFace so it fits in the top half of the "LCD display".
Make it as wide as possible using the control in the lower right corner.
Duplicatie this item and make it display the variable SlimStatus2.
Drag this field down, so it fits in the lower half of the "LCD display".
Click the Updat button to save your Control Page.
That's it!
I did not completely test this tutorial, so if you find any errors or ommisions, please send a PM and I'll fix as soon as possible.