Quick question if I may - so I understand the logic:
Based on the following, does this
wait 300 seconds and then execute the CURL command for a single IP - then go through the four commands (CURL) then repeat with the next IP?
OR
does this wait 300 seconds and execute that CURL command for all of the IPs in the list of IPs before proceeding to the next delayAndCurl?
repeat
set ipAddresses to paragraphs of (read file "MacHD:path:to:file.txt") -- change to proper path
repeat with anAddress in ipAddresses
delayAndCurl(300, "keypress/home", anAddress)
delayAndCurl(10, "launch/42088", anAddress)
delayAndCurl(15, "keypress/right", anAddress)
delayAndCurl(5, "keypress/select", anAddress)
end repeat
end repeat
The reason I am asking is to understand how to establish the timing(s) - ideally, it would wait 300 seconds, and then execute that “keypress/home” for each and every IP in the IP list, then proceed to the next delayAndCurl (10,
Sorry for my confusion, just want to see if I am understanding what is happening.
How would I structure it so that it would process all IPs for that command following the single delay value? The difference in timings becomes very large if it waits 300 seconds for one IP first command. Ideally, for timings, it would merely wait 300 seconds, then execute the CURL command for all IPs in the list, then proceed to the next delay/command. Such that the total delay is always about 300 seconds at the start whether 1 or 10 Roku devices.
try this, it waits 5 minutes before going through the address list and one second before each keypress/home address
repeat
set ipAddresses to paragraphs of (read file "MacHD:path:to:file.txt") -- change to proper path
delay 300
repeat with anAddress in ipAddresses
delayAndCurl(1, "keypress/home", anAddress)
delayAndCurl(10, "launch/42088", anAddress)
delayAndCurl(15, "keypress/right", anAddress)
delayAndCurl(5, "keypress/select", anAddress)
end repeat
end repeat
Ok, I see. So there is still the cumulative effect of executing each command in sequence for each IP, but this could be manageable for a list of perhaps ten (10) devices - would total somewhere close to 5 minutes to work it’s way through the list.
How would you structure it so that it executes them more together with less delay between commands if we needed the devices to be triggered at about the same time(s)?
Sort of like this logic/flow:
repeat
delay 300
do shell script "curl -d [url=http://192.168.0.x:8060/keypress/home]http://192.168.0.x:8060/keypress/home"[/url]
do shell script "curl -d [url=http://192.168.2.x:8060/keypress/home]http://192.168.2.x:8060/keypress/home"[/url]
do shell script "curl -d [url=http://192.168.2.x:8060/keypress/home]http://192.168.2.x:8060/keypress/home"[/url]
do shell script "curl -d [url=http://192.168.2.x:8060/keypress/home]http://192.168.2.x:8060/keypress/home"[/url]
do shell script "curl -d [url=http://192.168.3.x:8060/keypress/home]http://192.168.3.x:8060/keypress/home"[/url]
do shell script "curl -d [url=http://192.168.3.x:8060/keypress/home]http://192.168.3.x:8060/keypress/home"[/url]
delay 10
do shell script "curl -d [url=http://192.168.0.x:8060/launch/42088]http://192.168.0.x:8060/launch/42088"[/url]
do shell script "curl -d [url=http://192.168.2.x:8060/launch/42088]http://192.168.2.x:8060/launch/42088"[/url]
do shell script "curl -d [url=http://192.168.2.x:8060/launch/42088]http://192.168.2.x:8060/launch/42088"[/url]
do shell script "curl -d [url=http://192.168.2.x:8060/launch/42088]http://192.168.2.x:8060/launch/42088"[/url]
do shell script "curl -d [url=http://192.168.3.x:8060/launch/42088]http://192.168.3.x:8060/launch/42088"[/url]
do shell script "curl -d [url=http://192.168.3.x:8060//launch/42088]http://192.168.3.x:8060//launch/42088"[/url]
then the address iteration loop must be moved to the delayAndCurl handler
property logFileName : "myLog.txt"
property logFile : ""
set logFile to ((path to library folder from user domain as text) & "Logs:" & logFileName)
repeat
set ipAddresses to paragraphs of (read file "MacHD:path:to:file.txt") -- change to proper path
delayAndCurl(300, "keypress/home", ipAddresses)
delayAndCurl(10, "launch/42088", ipAddresses)
delayAndCurl(15, "keypress/right", ipAddresses)
delayAndCurl(5, "keypress/select", ipAddresses)
end repeat
on delayAndCurl(theDelay, thePath, addressList)
delay theDelay
repeat with anAddress in addressList
try
do shell script "curl -d http://" & anAddress & ":8060/" & thePath
on error errorMessage
writeToLog(thePath & " failed: " & errorMessage)
end try
end repeat
end delayAndCurl
on writeToLog(theMessage)
tell (current date) to set timestamp to short date string & space & time string & ": "
try
set fileReference to open for access file logFile with write permission
set logFileEof to get eof of the fileReference
write timestamp & theMessage & return to fileReference starting at eof as «class utf8»
close access fileReference
on error
try
close access file logFile
end try
end try
end writeToLog
Thank you Stefan! Brilliant! I am still making an effort to wrap my head around how you are able to come up with these solutions so quickly! Your brain works in amazing ways indeed.
Total newbie question, but on specifying the file path to the ip list:
must the path be included in quotes?
AND
is proper path specification with : or / ? - worried about the space in the Volume name “Macintosh HD”…
i.e, “Macintosh HD:Users:admin:Desktop:iplist.txt” or “/Users/admin/Desktop/iplist.txt”?
It’s quite like a real language. If you’re able to speak it, it’s quite easy to build the phrases
No, quotation is only needed in the shell environment
The native AppleScript path representation is HFS path (starting with a disk name and colon separated).
However nowadays some applications and Scripting Additions commands accept also POSIX paths (starting with a slash representing the startup volume and slash separated).
To point to the desktop I recommend to use the relative path
(path to desktop as text) & "iplist.txt"
which works regardless of the name of the startup volume and the name of the current user
When I try to implement the relative path to Desktop as:
repeat
set ipAddresses to paragraphs of (read file (path to desktop as text) & “iplist.txt”)
delayAndCurl(5, “keypress/home”, ipAddresses)
delayAndCurl(8, “launch/42088”, ipAddresses)
delayAndCurl(12, “keypress/right”, ipAddresses)
delayAndCurl(3, “keypress/select”, ipAddresses)
delay 300
end repeat
I get an error in Applescript Editor:
error "Can’t get file /“Macintosh HD: USers:admin:Desktop:".” number -1728 from file “Macintosh HD:Users:admin:Desktop:”
Also, I placed a delay of 600 seconds at the end of the commands within this repeat loop - for two reasons - first to be able to run the script and see results without having to wait 300 seconds - and second, to see if this will still work here such that there is about 5 minutes delay between the entire CURL command sequence running (all IPs inclusive)
Hi,
So far script is working like a charm. One question - on the LOG output, how can I make the AppleScript write the actual curl line/command that caused the error - ideally I need to see the IP address to know which device is having the issue. Right now, when I check the logs I get: