Hello, I am struggling with the script below, can anyone suggest why the “if result in window 1” does not work? The logic within the “if” condition never runs, yet the terminal has a “1” shown?? Any ideas?
tell application "Terminal"
(* initialize variables *)
set exit1 to false
launch
do script "TELNET" in window 1
delay 0.5
do script "TELNET 192.168.1.22 9999" in window 1
delay 0.5
do script "RFW 16" in window 1
delay 0.5
if result in window 1 contains "1" then
do script "WFW 9000, 999" in window 1
delay 0.5
do script "EXIT" in window 1
delay 0.5
set exit1 to true
end if
end tell
It now asks me for the Admin login credentials, once I enter those, the terminal app opens but nothing gets entered? Anyway to elliminate the logging in process?
set result1 to text returned of (do shell script “telnet 192.168.1.22 9999; rfw 16”)
if result1 contains “1” then
do shell script “telnet 192.168.1.22 9999; wfw 9000,999”
set exit1 to true
end if[/code]
Yes, I’d like the terminal window to be open. If I open the terminal window, anything using “do shell script” does not work, I am assuming this is only used when the terminal window is not open? It looks like all I can use is “do script xxxxx in window 1”, but then I cannot access the results displayed in the terminal window?
i believe so, that’s why i suggest doing my method. doing do shell script when opening the window will crash the system whereas doing my method should work. can you possibly do a combination of the two methods? what is it exactly you want to accomplish?
Contents of window x can give you the content of the window NOTE: only the content that is displaying!!!
Also you don’t need a terminal window open for do shell script. Terminal is an application that opens a shell and do shell script is part of an OSAX that opens a shell, executes and closes. These two have nothing in common with each other only that they both open a shell to the world of Darwin.
Do shell script can work but you need to use spawn and expect, same as like when you connect through SSH with another machine on through do shell script. Telnet commands mostly only useful with a complete session and not for every command a new session so what you’ll do with expect and spawn is what you do now in AppleScript. You do a command, expect some results and when it is true you do the next command until the session is complete.
I would like to use the “do script “xxxx” in window 1”, since it seems to work the best for me. I will be opeing various other applications (itunes and a powerpoint presentation) which will be the front window. Having the terminal window open would be better for me since I don’t have to keep attaching to the ethernet device (camera).
I see the reply anout using the “contents of window x”, I am assuming that this will give me the entire content of the window, is there anyway to just evaluate the response to the last terminal command?
Ok, the script below works, BUT, I would like the “result1” variable to only contain the response to the last terminal command “RFW 16”, since searching the whole content of the “window 1” may contain the response I am looking to receive, yet is may be for a past command? Any ideas?
tell application "Terminal"
(* initialize variables *)
set exit1 to false
launch
do script "telnet" in window 1
delay 0.5
do script "telnet 192.168.1.22 9999" in window 1
delay 0.5
do script "RFW 16" in window 1
delay 0.5
set result1 to contents of window 1
if result1 contains "1" then
do script "WFW 9000, 999" in window 1
delay 0.5
do script "EXIT" in window 1
delay 0.5
set exit1 to true
end if
end tell
The only problem with the method you mentioned is that I need to attach/detach from the camera for every command, I have a ton of commands to send. Also, the integration of this logic will be harder to do since I am not seeing any feedback because of the terminal not being open. I’d rather leave the terminal app open and issue “do script “xxxx” in window 1” commands, but I also need to be able to see each commands response? Is this a catch 22, it sounds like this can’t be done when the window is open? Is that correct?