View Full Version : How do I use way to monitor a change in a window's child name?

September 17th, 2015, 03:42 AM
I have started using Shairport so my iDaughter can use Airplay to any of the music zones in the house. It works perfectly, both from her iCrack and the Droids in the rest of the family (with AirAudio for Android). The only thing missing is a way to turn on the amp when playback starts and turn it off a couple of minutes after playback stops. I have gotten as far as to discover that the thing that changes, "Airport Name" which is a child and has the Child Name "READY" when not playing and another name, variable with what's playing, during playback. I tried using this code:

windowhandle = win.FindWindow(nil,"Stua")
windowhandle = tostring(windowhandle)
print (windowhandle)

win.EnumChildWindows (windowhandle (),EnumChildWinCallback)

But I have misunderstood something in the Enum stuff, since I keep getting an error (13: attempt to call global `windowhandle' (a string value)) or number value without the "tostring". If I use a slightly modified version of the code in Girder examples:


function EnumChildWinCallback (hwnd)
print (hwnd," ",win.GetWindowText (hwnd)," ",win.GetClassName (hwnd))
return 1

win.EnumChildWindows (win.GetForegroundWindow (),EnumChildWinCallback)

it will enumerate the child windows in the active window (which is why I have the win.Sleep since I have to click on the Shairport window to get it to work):

win.EnumChildWindows (win.GetForegroundWindow (),EnumChildWinCallback)
198002 nil Button
197896 Ready Static
132354 PushPin Button
132356 nil Button
197894 Airport Name Static
132224 nil Edit
197902 Change... Button
132370 Password Static
132368 nil Edit
132334 nil ComboBox
132324 nil Button
132322 Track Info Button
132320 --:-- Static
132318 nil Static
132316 --:-- Static
132314 nil Static
132312 nil Edit
132308 nil Edit
132306 nil Edit
132304 nil Button
132302 Play Button
132300 Play Button
132298 Play Button
132296 Play Button
132294 Play Button
132292 Play Button
132290 Play Button

The one I need is "197896 Ready Static". But the number does of course changes for each zone. Anyway I should be able to use string find on the full printout, right? So I cancheck if there's the text "Ready" or not somewhere in it. If it changes so there isn't "Ready" there I plan to turn on the amp in that zone, set a value of PlaybackStua = true (so it doesn't try to turn on the amp for each loop) and then turn off again the amp when PlaybackStua has been false for maybe two minutes. But first I have a problem getting from the handle of the window in the first part of the code to run the second part about the child windows, so I can use string find. Can somebody please put me out of my misery? :D

September 17th, 2015, 04:14 AM
Never mind, I got a step closer with a bit of searching on the forum. I get the printout I need with this simple code, but the string find wasn't as easy as I thought, of course. This code prints the stuff in the logger, but it doesn't turn it into a variable:

windowhandle = win.FindWindow(nil,"Stua")

StuaString = win.EnumChildWindows (windowhandle,EnumChildWinCallback)

if string.find (StuaString,'Ready') == true
then print("No playback here")

How come the printout isn't made into the variable StuaString? I get bad argument to string find since it can't find a string...

The function I use is this:

function EnumChildWinCallback (hwnd)
print (hwnd," ",win.GetWindowText (hwnd)," ",win.GetClassName (hwnd))
return 1

September 19th, 2015, 12:40 PM
Just saw my heading. Embarassing. I sound like a first grader... ;) But can somebody please help me with this? I really would like to get this for my iDaughter! I thought anything that could be printed, could be used as a variable in the same way, but I am obviously wrong. The line
StuaString = win.EnumChildWindows (windowhandle,EnumChildWinCallback)

only prints the names of the child windows, it doesn't copy anything to the variable StuaString which I thought I was creating.