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)
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)
on delayAndCurl(theDelay, thePath, addressList)
repeat with anAddress in addressList
do shell script "curl -d http://" & anAddress & ":8060/" & thePath
on error errorMessage
writeToLog(thePath & " failed: " & errorMessage)
tell (current date) to set timestamp to short date string & space & time string & ": "
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
close access file logFile
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:
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)
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)
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: