Making a list of several lists fails for me

set ip_t1 to "0.0.0.0" -- IP of Thecus #1
set ip_t2 to "0.0.0.0" -- IP of Thecus #2
set reboot_pw to "PASSWORD" -- Password of User reboot
set shutdown_pw to "PASSWORD" -- Password of User shutdown
set commands to {{"Reboot both", "Shutdown both"}, {"Reboot Thecus #1", "Shutdown Thecus #1"}, {"Reboot Thecus #2", "Shutdown Thecus #2"}}
set ping_result_1 to (do shell script "ping -c 1 -t 1 " & ip_t1 & "; echo -n") -- ping Thecus #1
set ping_result_2 to (do shell script "ping -c 1 -t 1 " & ip_t2 & "; echo -n") -- ping Thecus #2
set reboot_t1 to "plink -l reboot -pw " & reboot_pw & " " & ip_t1 -- command to reboot Thecus #1
set reboot_t2 to "plink -l reboot -pw " & reboot_pw & " " & ip_t2 -- command to reboot Thecus #2
set shutdown_t1 to "plink -l shutdown -pw " & shutdown_pw & " " & ip_t1 -- command to shutdown Thecus #1
set shutdown_t2 to "plink -l shutdown -pw " & shutdown_pw & " " & ip_t2 -- command to shutdown Thecus #2
(* 
Now we ping both machines to see whether they are turned on or off.
We set on/off for both machines, Thecus #1 is t1 and Thecus #2 is t2
*)
if ping_result_1 contains " 0.0% packet loss" then
	set t1 to "on"
else if ping_result_1 contains "100.0% packet loss" then
	set t1 to "off"
end if
if ping_result_2 contains " 0.0% packet loss" then
	set t2 to "on"
else if ping_result_2 contains "100.0% packet loss" then
	set t2 to "off"
end if
(* 
let's see which device is turned on
*)
if t1 = "on" and t2 = "on" then -- both are turned on
	set choice to choose from list commands with title "Thecus" with prompt "Reboot or Shutdown"
else if t1 = "on" and t2 = "off" then -- only Thecus #1 is turned on
	set choice to choose from list item 2 of commands with title "Thecus" with prompt "Reboot or Shutdown"
else if t1 = "off" and t2 = "on" then -- only Thecus #2 is turned on
	set choice to choose from list item 3 of commands with title "Thecus" with prompt "Reboot or Shutdown"
else if t1 = "off" and t2 = "off" then -- both are turned off
	display dialog "No Thecus turned on" buttons ["Abbrechen"] with title "Thecus" with icon stop
end if
(* 
Now we get to choose whether we want to reboot or shutdown the devices, 
depending on which devices are turned on 
*)
if choice is {"Reboot both"} then
	tell application "Terminal"
		activate
		do script reboot_t1
		delay 15
		do script reboot_t2
	end tell
else if choice is {"Shutdown both"} then
	tell application "Terminal"
		activate
		do script shutdown_t1
		delay 15
		do script shutdown_t2
	end tell
else if choice is {"Reboot Thecus #1"} then
	tell application "Terminal"
		activate
		do script reboot_t1
	end tell
else if choice is {"Shutdown Thecus #1"} then
	tell application "Terminal"
		activate
		do script shutdown_t1
	end tell
else if choice is {"Reboot Thecus #2"} then
	tell application "Terminal"
		activate
		do script reboot_t2
	end tell
else if choice is {"Shutdown Thecus #2"} then
	tell application "Terminal"
		activate
		do script shutdown_t2
	end tell
end if

My script automates the shutting down or rebooting of my two NAS devices (from Thecus). The reboot/shutdown is just done by logging on to the devices with either the user shutdown or reboot. To be able to directly send the password on the terminal I’m using PuTTY (that’s why there is the plink call). The script is intended to give me varios options, depending on which device is currently turned on or if both are turned on.
My problem is that when both are turned on, line 30 (set choice to choose from list commands with title “Thecus” with prompt “Reboot or Shutdown”) will not work. The error is that “{“Reboot both”, “Shutdown both”} can not be turned in type string” or similar, the error is in German here). So the problem is with the list of lists in line 5, picking one list out works, but just picking the whole list of lists fails.
I tried it with
set choice to choose from list of items 1 thru 3 of commands with title “Thecus” with prompt “Reboot or Shutdown”

But that fails as well.
I’m just not getting what I’m doing wrong here. Can you help me?

HI,

choose from list requires a list of items (strings or numbers), a nested list doesn’t work

Hmmm, too bad, I hoped I could write it like that. Seems I need to do three lists :slight_smile:

No, one list is sufficient


.
set commands to {"Reboot both", "Shutdown both", "Reboot Thecus #1", "Shutdown Thecus #1", "Reboot Thecus #2", "Shutdown Thecus #2"}

.
(* 
let's see which device is turned on
*)

if t1 = "off" and t2 = "off" then -- both are turned off
	display dialog "No Thecus turned on" buttons ["Abbrechen"] with title "Thecus" with icon stop
else if t1 = "on" and t2 = "on" then -- both are turned on
	copy commands to cmdList
else if t1 = "on" and t2 = "off" then -- only Thecus #1 is turned on
	set cmdList to items 3 thru 4 of commands
else if t1 = "off" and t2 = "on" then -- only Thecus #2 is turned on
	set cmdList to items 5 thru 6 of commands
end if
set choice to choose from list cmdList with title "Thecus" with prompt "Reboot or Shutdown"
if choice is false then return
(* 
Now we get to choose whether we want to reboot or shutdown the devices, 
depending on which devices are turned on 
*)



LOL - thanks!
I was so set on using three lists that I overlooked that I could just write one big list and just use the items I need EVEN THOUGH I was using the items stuff :slight_smile:

Thanks for that and the additional tweaking