use "expect"
http://en.wikipedia.org/wiki/Expect
-Ruairi
On Jun 29, 2006, at 2:31 PM, Kimo Johnson wrote:
Hi,
I'm looking for a way to send commands to an interactive program
(matlab, python) running in Terminal. I have found 3 partial
solutions, none are exactly what I would like, but all are close.
In TextWrangler, I can highlight text and then hit a keystroke to
run a script on the selected text. I would like to be able to
send this text to a currently running matlab or python session
(ideally without bringing Terminal to the front every time). Here
are the 3 partial solutions:
1) Use Terminal's "do script in window" capability
tell application "Terminal"
do script text_to_execute in window 1
end tell
This works great for sending commands to a shell prompt without
opening a new window each time. If I start an interactive
program, however, the commands are no longer sent to the terminal.
2) Use System Events to type the string
tell application "Terminal"
activate
tell application "System Events"
keystroke text_to_execute
end tell
end tell
This works as well, though I need to bring Terminal to the
front. The problem is that if I assign a keystroke in
TextWrangler to execute this script, the keystroke seems to
interfere with the call to System Events. For example, if the
keystroke to execute the script has "command" in it and the string
I'm trying to send has an "s", Terminal seems to get "command-s."
If I execute the script by clicking the run button, it works fine.
3) Use iTerm instead of Terminal
tell application "iTerm"
tell current session of current terminal
write text text_to_execute
end tell
end tell
This works the best of the three. Actually, it works perfectly
for what I'm trying to do. I would rather not use iTerm though
because of some unrelated bugs that make it not as nice as
Terminal for interactive applications.
So the final question is: can I get the "do script in window"
version (#1) to work if a program is running in the terminal?
Thanks.
Kimo
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list (Applescript-
email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/ruairi%
40euro.apple.com
This email sent to email@hidden
--
Regards
RuairĂ O'Mahony
STE Automation
+ 353 (0)21 428 4393