• 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: First Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: First Applescript


  • Subject: Re: First Applescript
  • From: Graff <email@hidden>
  • Date: Tue, 18 May 2004 18:38:12 -0400

First of all, do you want to do this with AppleScript or with the shell? If you want to you can call shell commands from AppleScript, or you can do the script all in AppleScript, or you can do it all in the shell.

For AppleScript your best bet is to do this in an idle handler. A handler is the equivalent of a function for other programming languages. There are certain handlers for an AppleScript applications and one of them is an idle handler, it gets called every so often so that the script application can do stuff. Here is an example:
----
on idle
-- check if program is running
-- if it is not running launch it
return 5 * minutes -- check again in 5 minutes
end idle
----

The return statement sets the timer, it is in the number of seconds (it can be partial seconds also I believe). minutes is a constant that resolves to 60 so 5 * 60 = 300. Thus "return 5 * minutes" means execute the idle handler again in 300 seconds.

What you want to do is to use the Finder or System Events to get a list of running applications, then go through that list and see if your application is in the list. If not then you send the application a tell message and tell it to launch.

- Ken

On May 18, 2004, at 4:48 PM, Web Manager wrote:

Hi List,

I must confess up front that I am a recent PC convert and that this is my
*first* task in Applescript. I don't really have an execution question yet
as much as an approach question. Here is what I want to accomplish.

I want to see if a particular process is running,
if the process is running I want the script to sleep for 5 minutes and try
again
if the process has stopped I want it to re-launch the associated application
sleep for 5 minutes and try again.

I can do this with AutoIT on the PC side no problem but since this is my
first Applescript I'm not sure what to do first, here is my question.

Do I actually have to open something like Terminal > run top > look for
'such&such process' and then manipulate it or can I just create an if
statement to accomplish the whole thing...

Something like this (pardon my ignorance):

if such&such process is running wait 5 minutes
else start such&such application and wait 5 minutes & loop
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


References: 
 >First Applescript (From: "Web Manager" <email@hidden>)

  • Prev by Date: Re: Finding the oldest date in a list
  • Next by Date: Controlling caps lock?
  • Previous by thread: Re: First Applescript
  • Next by thread: Re: First Applescript
  • Index(es):
    • Date
    • Thread