• 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
Re: Make New Window in Terminal...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Make New Window in Terminal...


  • Subject: Re: Make New Window in Terminal...
  • From: Graff <email@hidden>
  • Date: Sat, 25 Sep 2004 12:53:30 -0400

Running a script in the background is not that tough, what you need to do is redirect all output to somewhere other than a shell and then background the script. For example:

    do shell script "echo 'This is a test' > ~/Desktop/test.txt 2>&1 &"

This will create a file named "test.txt" on the current user's desktop that contains the text "This is a test". The command will run in the background. You can do this with pretty much every shell command, except for the ones that require interaction. For those you will need to use the shell tool "expect" or something similar.

You can keep tabs on the output of a process by getting the tail of the file that contains the re-directed output, if you need it.

This is all covered in this Technote:
<http://developer.apple.com/technotes/tn2002/tn2065.html>

That being said, there is nothing particularly wrong with using Terminal to do the dirty work other than the fact that involving another application in a script can present extra complications. Like, what if the app crashes, or what if the user cancels the process himself, or what if the user removed the application from his system, and so on. As long as you go into this with those sort of considerations in mind then there should be little trouble.

- Ken

On Sep 25, 2004, at 12:08 PM, David Crowe wrote:

I have found that running scripts in the background is difficult to make work with "do shell script". Besides, if you want to see the status of the process it's a lot easier to open the terminal window. Since my script can automatically hide the Terminal application I hardly know it's there.

I think what I am going to do is to give the window for my particular application a particular name and then, when running the script, check to see if that window exists, and then use it. If not I will just run the script without specifying a window which will cause Terminal to create one. This also avoids me running ssh in a window where I was in the midst of doing something else.

At 5:18 PM -0700 9/24/04, Andrew Oliver wrote:
On 9/24/04 1:48 PM, "David Crowe" <email@hidden> wrote:

Half the time after posting to this email list I feel dumb ... like now.


I was performing my script in Window 1 to avoid a proliferation of windows. That works great if there is a window 1.

Beware!

This is all well and good provided you know what window 1 is doing.
However, you're royally screwed is window 1 is doing something else - like
maybe it's got an open ssh session to another machine, in which case you
start blindly running your 'do script's on some other machine. Bad. Very
bad.


 I guess what I should do is run my script in a window with a
 particular name and then check for that name and, if a window with
 that name exists, use it, otherwise just run the script and let it
 create a new window.

Well, if you really need to run in in the terminal at all[1] you may find it
better to run your first command as a 'do script', letting it open a new
window, then run subsequent 'do script' commands with an associated 'in
window x' to send them to the same place. That way you're guaranteed to not
walk all over some other terminal process.


[1] I may have missed an earlier part of the discussion where you stated the
need to use terminal.app rather than 'do shell script'.

_______________________________________________ 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: Make New Window in Terminal...
      • From: "John W. Baxter" <email@hidden>
References: 
 >Re: Make New Window in Terminal... (From: Andrew Oliver <email@hidden>)
 >Re: Make New Window in Terminal... (From: David Crowe <email@hidden>)

  • Prev by Date: Re: Make New Window in Terminal...
  • Next by Date: Really, really simple solution to Terminal window issue...
  • Previous by thread: Re: Make New Window in Terminal...
  • Next by thread: Re: Make New Window in Terminal...
  • Index(es):
    • Date
    • Thread