Re: Can AppleScript determine if a shell process is running?
Re: Can AppleScript determine if a shell process is running?
- Subject: Re: Can AppleScript determine if a shell process is running?
- From: Christopher Stone <email@hidden>
- Date: Sun, 21 Sep 2014 21:48:35 -0500
[Whups. I sent this direct.]
On Sep 20, 2014, at 15:53, Lists <email@hidden> wrote:
>
> I'm considering creating a toggle for a couple of shell processes I run occasionally. I would like to be able to start a shell process if it isn't running and shut it down if it is.
______________________________________________________________________
Hey J,
You can use the shell.
try
set _process to do shell script "ps auxc | egrep -i 'Finder'"
on error
set _process to false
end try
(Backticks indicate a Unix Executable.)
You MAY have to have the xCode installed for this, but as of Mountain Lion (if memory serves) `pgrep` and `pkill` are available in the shell.
pgrep -il "Finder"
-i is case-insensitive.
-l is long (prints file name in addition to PID).
try
set _process to do shell script "pgrep -i 'Finder'"
on error
set _process to false
end try
You have `kill` and `killall` available for terminating a process.
`open` for opening a process.
Help (Terminal):
man <command>
Remember though that man pages are often painfully opaque, and it's frequently necessary to look to Google for good examples.
--
Best Regards,
Chris
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden