Re: Relaunching App Programmatically - Terminal Window Shows up
Re: Relaunching App Programmatically - Terminal Window Shows up
- Subject: Re: Relaunching App Programmatically - Terminal Window Shows up
- From: Oleg Krupnov <email@hidden>
- Date: Mon, 23 Feb 2009 11:01:41 +0200
Hi Daniel,
Thanks! I have found a better approach though, IMHO. I pass the path to the
application bundle and also the process ID as two args to the script ($1,
$2). In result, I make sure that exactly the calling process is shut down,
and exactly the same executable is relaunched. The only "problem" that
remains is that if more instances of the same bundle with the same path are
already launched, a new instance is not created, but activated an existing
one. Though I believe, this behavior is perfectly valid, because if one
clicks the bundle in Finder, the same thing happens.
Here is my code:
i="10"
while [ $i -gt 0 ]
do
sleep 1
is_running=$(osascript -e 'tell application "System Events" to exists
(process 1 whose unix id is '$2')')
echo "Waiting for shutdown: " $is_running
if [ "$is_running" = "false" ]; then
i="0"
else
i=$(($i - 1))
fi
done
# relaunch the app
osascript -e 'tell application "'"$1"'" to activate'
On Mon, Feb 23, 2009 at 10:52 AM, Daniel Waylonis <email@hidden> wrote:
> On Feb 22, 2009, at 10:46 AM, Oleg Krupnov wrote:
>
> Thanks, Dan! Sorry for the delay. Your code really works, and I likely will
> use it. I only have a little doubt in that if I refer to the app by its
> name, problems may occur when there are multiple instances of the app
> running at the same time, or there are multiple copies on disk. Have you
> thought about it?
>
>
> Hi Oleg,
>
> It's possible. You could check the bundle identifier of the process in
> AppleScript as well:
>
> tell application "System Events"
> try
> bundle identifier of process "<your application>"
> end try
> end tell
>
> This will return the bundle ID and you can compare it against what you
> expect.
>
> Dan
>
> -----------------------------------------------------------------
>
> *Dan Waylonis** **email@hidden*
>
> nekotech SOFTWARE
>
> http://www.nekotech.com
>
> 650.887.3711
>
>
>
>
>
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden