Morning Folks,

think this is my first post of the new year, so Happy New Year.... i have got a small applescript i have written (see below), it is connecting to a telnet session, but opens two terminal windows - one is just a terminal window and the other is the telnet session...any ideas on how i can remove the first winow opening to just leave the actual telnet session??

set telnet to "telnet -K 0.0.0.0
tell application "Terminal"
run
do script telnet
delay 1
end tell


Thanks a lot

gn0m3

try adding this after the 'run' statement:

tell application "System Events"
tell process "Terminal"
keystroke "w" using {command down}
end tell
end tell

when the run statement is given, it opens Terminal, which by default opens a new sessions window. The above code sends the command-w keystroke to the terminal app via a system event (same as a live keystroke) and will close the open window. Good luck.

Just change the script to read

[tell application "Terminal"
activate
end tell
delay 5
tell application "System Events"
if UI elements enabled then
tell process "Terminal"
set frontmost to true
end tell

keystroke "telnet -K 0.0.0.0"

key down return
key up return

end if
end tell]

Type the text in the [] in script editor and it will tell terminal to try to connect to 0.0.0.0. You can change it to whatever you want. This script basically just presses the keys on the keyboard for you. (And you only have one window open on the run)

Hope that works :)

thanks for that guys, will try it out later, have been off ill for the last week so sorry for not responding...

gn0m3

thanks Lomoco, that worked great. Thanks also for your suggestion cryptq, but when run the front window got closed down which was the window i needed, i tried playing around with the code but could not get to function..

Thank you both.

gn0m3

Oh, and be sure not to do anything while the script is running. It may cause your computer to start acting funny. If this occurs, save whatever you were working on by using the MENUS and log-out. What happened is that a key that applescript pressed didn't get let up and is still being held down virtually. Experiment with the script I gave you to get the best result for you.

try adding this after the 'run' statement:

tell application "System Events"
tell process "Terminal"
keystroke "w" using {command down}
end tell
end tell

when the run statement is given, it opens Terminal, which by default opens a new sessions window. The above code sends the command-w keystroke to the terminal app via a system event (same as a live keystroke) and will close the open window. Good luck.

Modify your command-w script to read the following:

tell application "System Events"
tell process "Terminal"
keystroke "`" using {command down}
keystroke "w" using {command down}
end tell
end tell

That should work for you

thanks once again for your help on this one guys, another problem solved.

gn0m3

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.