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.



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:
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>)



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.