Curl and awk with AppleScript

Hi all,
I have a network controlled power strip and I’m looking for a way to get the state of the power slots and controlling it via AppleScript and from that maybe try and get a gui working.

So far the state of the slots can be read out via the command

strg.cfg looks like this

That’s name of the slot; on/off; locked on/of; unknown

With the awk script slots.awk and the following command line I get a nicer terminal printout:

the slots.awk file

and the terminal output is

Now I wonder who to get all this into variables in Applescript, right now I haven’t used AppleScript for a while and I never quite understood how to parse a text file.

If anyone is interested, you can toggle the slots by using the command
curl --silent --user user:password --data “F0=S” http://IP-address/ctrl.htm
with slots numbered 0-7 (and sadly toggling like this doesn’t honor the locked bit) but once I get to understand how to properly parse the strg.cfg I know how to to write the toggle.


the config file is a simple semicolon separated text.

With AppleScript text item delimiters you can deserialize the text to 8 lists containing the name and the 4 parameters respectively, for example

[format]{“iMac”, “1”, “1”, “37”, “”}[/format]

Then you can change a parameter and serialize the text back to CSV

set cfg to "iMac;1;1;37;;Monitor;1;0;0;;Thunderbolt;1;0;0;;TimeMachine;0;0;0;;USB;1;0;0;;Lacie Stereo;0;0;0;;Rland MacMini;0;0;0;;Scanner;0;0;0;;end"

set deviceList to {}
set {TID, text item delimiters} to {text item delimiters, ";"}
set parameters to text items of cfg

repeat with i from 1 to ((count parameters) - 1) by 5
	set end of deviceList to items i thru (i + 4) of parameters
end repeat

-- set the second parameter of the forth device to 1
set item 3 of item 4 of contents of deviceList to "1"

-- serialize the list back
set newCfg to (deviceList as text) & ";end"
set text item delimiters to TID