• 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: Finding out is an Application is running
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Finding out is an Application is running


  • Subject: Re: Finding out is an Application is running
  • From: Christopher Nebel <email@hidden>
  • Date: Wed, 11 Feb 2004 15:27:52 -0800

On Feb 11, 2004, at 12:57 PM, Andrew wrote:

I was wondering if there was any way of figuring out if an application file
at some path is currently running. The way I do it now is...

First, System Events is really the one responsible for handling "process". You can tell the Finder (which used to handle it in Mac OS 9), and it'll get forwarded, but I prefer to be direct.

If you know the name of the application, this is trivial:

on appIsRunning(applicationName)
tell application "System Events"
return (exists process applicationName)
end
end

If you really want it based on a path, then it's a bit harder, since System Events doesn't like "whose" clauses that compare files, but still not too bad:

on appIsRunning(applicationPath)
-- ideally, you'd say "exists first process whose file
-- is (alias applicationPath)", but that doesn't work, so...
tell application "System Events"
set allFiles to file of every process
end
return (alias applicationPath) is in allFiles
end

Remember: "exists", "every", and "whose" are your friends. (When they work, that is.) Incidentally, the problem of "ps -ax" truncating the paths? That's what the "-w" option is for. Use three to get completely untruncated paths, like this: "ps -axwww".


--Chris Nebel
AppleScript Engineering

On Feb 11, 2004, at 12:57 PM, Andrew wrote:

I was wondering if there was any way of figuring out if an application file
at some path is currently running.

The way I do it now is by the insane :

on appIsRunning(applicationFile)
tell application "Finder"
set processList to every process
repeat with myIndex from 1 to number of items in processList
set systemProcess to item myIndex of processList
if (exists application file (application file of systemProcess
as string)) then -- this junk is here to get around a bug in Applescript
set testApp to application file (application file of
systemProcess as string)
if (testApp as string = applicationFile as string) then
return true
end if
end if
end repeat
end tell
return false
end appIsRunning
_______________________________________________
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.

  • Follow-Ups:
    • Re: Finding out is an Application is running
      • From: Andrew <email@hidden>
    • Re: Finding out is an Application is running
      • From: Emmanuel <email@hidden>
References: 
 >Finding out is an Application is running (From: Andrew <email@hidden>)

  • Prev by Date: On Run handlers
  • Next by Date: Re: Error in the Finder
  • Previous by thread: Re: Finding out is an Application is running
  • Next by thread: Re: Finding out is an Application is running
  • Index(es):
    • Date
    • Thread