telnet

Hi all,

Please forgive any ignorance on my part :slight_smile: I’m new to AppleScripting and I’m obviously in over my head.

I think what I’m trying to do is fairly straight forward, but I’m having problems.

I’m trying applescript a telnet session that will open terminal, telnet to a server, and when the telnet is exited, close the terminal application.

I’ve hit a snag right off the bat. My script will open the terminal, but when trying to start the telnet, I get the following error:

Terminal got an error: Connection closed by foreign host.

I’m not sure why. Here’s the code so far:

set hostname to "save.pbpost.com"

tell application "Terminal"
	run
	do shell script "telnet " & hostname
end tell

Like I said, its primitive, but I thought at least the telnet would work. Any ideas/suggestions?

If you’re scripting Terminal you want to use ‘do script’:

tell application "Terminal"
	run
	do script "telnet save.pbpost.com"
end tell

‘do shell script’ is not part of Terminal’s dictionary. It’s for using shell commands without using Terminal.

Thanks. That worked fine. My question now is that the script opens two windows: 1. a Terminal window; 2. a Terminal window with the telnet session started. Is there a way to dump that first window? And I might as well ask, is there any kind of easy way to autoclose the or script the closing of the window when the telnet session ends?

Sorry to be a pain in the ass, but this kinda got dumped on me…


tell application "Terminal"
	run
	do script "telnet save.pbpost.com"
end tell

Yes. Try this:

tell application "Terminal"
	run
	if (count windows) is 0 then do script ""
	
	do script "telnet save.pbpost.com" in front window
end tell

Not that I’m aware of.

Once again, many thanks. Hopefully this will work for the end user, if not, I know I’ll use it myself.

I was browsing the forums and did notice someone asking about a script to kill a process (http://bbs.applescript.net/viewtopic.php?id=12870). Do you think its possible to put some sort of if/then statement in there that if/when the process ends, to kill the window?

Gad I feel so inadequate :slight_smile:

The AppleScript doesn’t wait for the ‘do script’ statement to end. If that doesn’t make sense, then try this script:

tell application "Terminal"
	run
	if (count windows) is 0 then do script ""
	
	do script "telnet save.pbpost.com" in front window
	quit
end tell

I see what you’re getting at with that last one. Thanks. This has been an eye opener.

This post has helped me out… But, unlike the fella before me, I need to login also, with username and password. Any ideas how to do this in the code without having to send keystrokes?