HELP Applescript for telnet

Discussion in 'Mac Programming' started by SOOMINAHN, Dec 26, 2012.

  1. SOOMINAHN, Dec 26, 2012
    Last edited by a moderator: Dec 26, 2012

    SOOMINAHN macrumors newbie

    Dec 26, 2012
    Hello everyone.

    I would like to know correct script for telnet connection.
    Below script is one I made. But it is not working.
    Especially I don't know what I should use keyword or command on red part.

    launch "iTerm"
    tell application "iTerm"
    	set myterm to (make new terminal)
    	tell myterm
    		launch session "Default Session"
    		tell the last session
    			write text "telnet 2001"
    			write text "enable"
    			write text "password"
    			write text "reload"
    			[COLOR="Red"]if output = [/COLOR]"System configuration has been modified. Save? [yes/no]:" then
    				write text "n"
    			[COLOR="red"]else if output = [/COLOR]"Proceed with reload? [confirm]" then
    				write text "y"
    			end if
    		end tell
    	end tell
    end tell
    Please teach me how solve this problem.
    Thank you for your attention.
  2. numero macrumors regular

    Jul 23, 2002
    As you already know, your output lines won't work.

    The 2 ways that this could work (but doesn't) is as follows:
    1) The "write text 'blah, blah, blah" line would return a value which is either an empty string for a command that was accepted or the text that the process the terminal is communicating with returned. iTerm doesn't do this. "Write" does not return anything.

    2) iTerm provides a "contents" property of the "session". This sounds like it would return all of the text of the session and you would have to sort though that looking for the last line. When I ran it got back nothing. The compiler even changed my "get contents" to "get text" inside of my "tell last session" block.

    What you might be left with is using System Events to do a command-a, command-c to get the contents of the window to the clipboard and then pick through that to find out what the last line of text contains.

Share This Page