Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Script to run a command in new Terminal window works un-reliably.



Now I remember why I needed all that long long script :-(. It looks like,  your version will produce one extra empty Terminal window in case when Terminal application was not running.


On Jul 27, 2006, at 12:51 PM, Andrei Tchijov wrote:

Wow...!!!
What do you know, it does work. Thanks a lot Andrew. 

Now, just one more thing left to figure out.  To simulate "-K" (Clear Scrollback) command, should I do "tell application "System Events" .... click menu item "Clear Scrollback" ..... end tell"  (the same way as "New Shell" get invoked in the original script ) or there is better way?

Thanks a lot again,

Andrei Tchijov 

On Jul 27, 2006, at 12:09 PM, Andrew Oliver wrote:

Hi,
  Could some one take a look at the script below and tell me what could be wrong with it?  The goal is to create new Terminal window and run a command in it.  The script works most of the time, but once in a while, it will fail to do "run command" bit.  

The first question is why you need to run this in terminal at all? Would 'do shell script' not suffice?

Secondly, assuming that using terminal.app is needed, your entire script can be compressed to:

 tell application "Terminal" to do script "command to run"

That's it. It will automatically launch terminal.app if it's not running, and will automatically start a new shell to run the command in. You have to go our of your way (e.g. use 'in window x') if you want a command to run in an existing window, so why make more work for yourself?

Andrew
:)

On Jul 27, 2006, at 8:58 AM, Andrei Tchijov wrote:


P.S. I am not sure if it make a difference, but I am running this script via the shell using osascript .
P.P.S. Though "activate" in the last "tell application ..." seems redundant, I think it did improve reliability of the script. 
===================================================================
tell application "System Events"
if not (exists process "Terminal") then
tell application "Terminal"
activate
end tell
else
tell application "Terminal"
activate
end tell
tell application "System Events"
tell process "Terminal"
tell menu bar 1
tell menu bar item "File"
tell menu "File"
click menu item "New Shell"
end tell
end tell
end tell
end tell
end tell
end if
tell application "Terminal"
activate
do script "<command to run>" in the front window
end tell
end tell

 _______________________________________________
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


 _______________________________________________
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

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-users/email@hidden

This email sent to email@hidden

References: 
 >Script to run a command in new Terminal window works un-reliably. (From: Andrei Tchijov <email@hidden>)
 >Re: Script to run a command in new Terminal window works un-reliably. (From: Andrew Oliver <email@hidden>)
 >Re: Script to run a command in new Terminal window works un-reliably. (From: Andrei Tchijov <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.