• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
send commands to interactive prompt
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

send commands to interactive prompt


  • Subject: send commands to interactive prompt
  • From: Kimo Johnson <email@hidden>
  • Date: Thu, 29 Jun 2006 09:31:20 -0400

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      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: send commands to interactive prompt
      • From: "RuairĂ­ O' Mahony" <email@hidden>
  • Prev by Date: AppleEvent for fast user switching?
  • Next by Date: Re: Handler query - exchanging values
  • Previous by thread: AppleEvent for fast user switching?
  • Next by thread: Re: send commands to interactive prompt
  • Index(es):
    • Date
    • Thread