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?