# [PATCH] git-gui: bring Wish process to front on Mac

8 messages from 2013-06-06 to 2013-06-15. Participants: Stefan Haller, Pat Thoyts, Junio C Hamano.
Thread: https://gitlist.dev/t/34037

## Stefan Haller, 2013-06-06 08:17

Subject: [PATCH] git-gui: bring Wish process to front on Mac
Message-ID: <1370506667-24576-1-git-send-email-stefan@haller-berlin.de>
URL: https://gitlist.dev/e/1370506667-24576-1-git-send-email-stefan%40haller-berlin.de

```
On Mac OS X, any application that is started from the Terminal will open
behind all running applications; as a work-around, manually bring ourselves
to the front. (Stolen from gitk, commit 76bf6ff93e.)

We do this as the very first thing, so that any message boxes that might pop
up during the rest of the startup sequence are actually seen by the user.

Signed-off-by: Stefan Haller <stefan@haller-berlin.de>
---
 git-gui.sh | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/git-gui.sh b/git-gui.sh
index e133331..c464928 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -29,6 +29,19 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA}]
 
 ######################################################################
 ##
+## On Mac, bring the current Wish process window to front
+
+if {[tk windowingsystem] eq "aqua"} {
+	exec osascript -e [format {
+		tell application "System Events"
+			set frontmost of processes whose unix id is %d to true
+		end tell
+	} [pid] ]
+}
+
+
+######################################################################
+##
 ## Tcl/Tk sanity check
 
 if {[catch {package require Tcl 8.4} err]
-- 
1.8.3.14.g33f718c

```

## Pat Thoyts, 2013-06-06 14:09

Subject: Re: [PATCH] git-gui: bring Wish process to front on Mac
Message-ID: <CABNJ2G+h3zh+=wLA0KHjUn8TsfhqUK1Kn-1_=6hnXVRJUPhuuA@mail.gmail.com>
URL: https://gitlist.dev/e/CABNJ2G%2Bh3zh%2B%3DwLA0KHjUn8TsfhqUK1Kn-1_%3D6hnXVRJUPhuuA%40mail.gmail.com
In-Reply-To: <1370506667-24576-1-git-send-email-stefan@haller-berlin.de>

```
On 6 June 2013 09:17, Stefan Haller <stefan@haller-berlin.de> wrote:
> On Mac OS X, any application that is started from the Terminal will open
> behind all running applications; as a work-around, manually bring ourselves
> to the front. (Stolen from gitk, commit 76bf6ff93e.)
>
> We do this as the very first thing, so that any message boxes that might pop
> up during the rest of the startup sequence are actually seen by the user.
>
> Signed-off-by: Stefan Haller <stefan@haller-berlin.de>
> ---
>  git-gui.sh | 13 +++++++++++++
>  1 file changed, 13 insertions(+)
>
> diff --git a/git-gui.sh b/git-gui.sh
> index e133331..c464928 100755
> --- a/git-gui.sh
> +++ b/git-gui.sh
> @@ -29,6 +29,19 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA}]
>
>  ######################################################################
>  ##
> +## On Mac, bring the current Wish process window to front
> +
> +if {[tk windowingsystem] eq "aqua"} {
> +       exec osascript -e [format {
> +               tell application "System Events"
> +                       set frontmost of processes whose unix id is %d to true
> +               end tell
> +       } [pid] ]
> +}
> +
> +
> +######################################################################
> +##
>  ## Tcl/Tk sanity check
>
>  if {[catch {package require Tcl 8.4} err]
> --
> 1.8.3.14.g33f718c
>

Seems fine to me. I can't test this as I have no access to this
platform. Possibly you should run this in a catch statement so it can
ignore any errors and I would tend to use the 'auto_execok' command to
ensure that osascript actually exists. Something like

  set arg [format {tell application......}]
  catch {exec {*}[auto_execok osascript] -e $arg [pid]}

but possibly this is guaranteed to exist on all macs which would make
the above redundant. What I'm thinking is you dont want the app to
exit just because something goes wrong in this call.

```

## Stefan Haller, 2013-06-06 17:12

Subject: Re: [PATCH] git-gui: bring Wish process to front on Mac
Message-ID: <1l424u5.uk987q18u3oxfM%lists@haller-berlin.de>
URL: https://gitlist.dev/e/1l424u5.uk987q18u3oxfM%25lists%40haller-berlin.de
In-Reply-To: <CABNJ2G+h3zh+=wLA0KHjUn8TsfhqUK1Kn-1_=6hnXVRJUPhuuA@mail.gmail.com>

```
Pat Thoyts <patthoyts@gmail.com> wrote:

> On 6 June 2013 09:17, Stefan Haller <stefan@haller-berlin.de> wrote:
> > +## On Mac, bring the current Wish process window to front
> > +
> > +if {[tk windowingsystem] eq "aqua"} {
> > +       exec osascript -e [format {
> > +               tell application "System Events"
> > +                       set frontmost of processes whose unix id is %d to true
> > +               end tell
> > +       } [pid] ]
> > +}
> 
> Seems fine to me. I can't test this as I have no access to this
> platform. Possibly you should run this in a catch statement so it can
> ignore any errors and I would tend to use the 'auto_execok' command to
> ensure that osascript actually exists. Something like
> 
>   set arg [format {tell application......}]
>   catch {exec {*}[auto_execok osascript] -e $arg [pid]}
> 
> but possibly this is guaranteed to exist on all macs which would make
> the above redundant. What I'm thinking is you dont want the app to
> exit just because something goes wrong in this call.

I don't think we need auto_execok here, as osascript is available on
every Mac system. We might even specify the exact path, it's always
/usr/bin/osascript. Is that preferable?

I agree that "catch" might be a good idea though. It raises two
questions though:

1) Should we make the same change in gitk then? It already has the same
   code without the catch (released in 1.8.3 already, btw).

2) Should we think about some way of sharing code between gitk and
   git gui, so that these kinds of changes don't have to be made twice?


-- 
Stefan Haller
Berlin, Germany
http://www.haller-berlin.de/

```

## Junio C Hamano, 2013-06-06 18:15

Subject: Re: [PATCH] git-gui: bring Wish process to front on Mac
Message-ID: <7vk3m7yukc.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vk3m7yukc.fsf%40alter.siamese.dyndns.org
In-Reply-To: <CABNJ2G+h3zh+=wLA0KHjUn8TsfhqUK1Kn-1_=6hnXVRJUPhuuA@mail.gmail.com>

```
Pat Thoyts <patthoyts@gmail.com> writes:

> Seems fine to me. I can't test this as I have no access to this
> platform. Possibly you should run this in a catch statement so it can
> ignore any errors and I would tend to use the 'auto_execok' command to
> ensure that osascript actually exists. Something like
>
>   set arg [format {tell application......}]
>   catch {exec {*}[auto_execok osascript] -e $arg [pid]}
>
> but possibly this is guaranteed to exist on all macs which would make
> the above redundant. What I'm thinking is you dont want the app to
> exit just because something goes wrong in this call.

Sounds like a sensible concern; gitk in v1.8.3 has it without catch
so we may see failure reports from OSX users soonish, in which case
both this patch and gitk need to be updated for it.

Stefan (as your name appears in 76bf6ff93e, I am assuming that you
were the OSX-osascript guru in that commit) could you keep an eye on
the list traffic to see if users of latest gitk have issues with
that change, please?

Thanks.

```

## Stefan Haller, 2013-06-07 21:56

Subject: [PATCH v2] git-gui: bring Wish process to front on Mac
Message-ID: <1370642211-34416-1-git-send-email-stefan@haller-berlin.de>
URL: https://gitlist.dev/e/1370642211-34416-1-git-send-email-stefan%40haller-berlin.de
In-Reply-To: <1l424u5.uk987q18u3oxfM%lists@haller-berlin.de>

```
On Mac OS X, any application that is started from the Terminal will open
behind all running applications; as a work-around, manually bring ourselves
to the front. (Stolen from gitk, commit 76bf6ff93e.)

We do this as the very first thing, so that any message boxes that might pop
up during the rest of the startup sequence are actually seen by the user.

Signed-off-by: Stefan Haller <stefan@haller-berlin.de>
---
Changes since the first patch: 
 - add catch
 - specify full path to /usr/bin/osascript

 git-gui.sh | 15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/git-gui.sh b/git-gui.sh
index e133331..a792924 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -29,6 +29,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA}]
 
 ######################################################################
 ##
+## On Mac, bring the current Wish process window to front
+
+if {[tk windowingsystem] eq "aqua"} {
+	catch {
+		exec /usr/bin/osascript -e [format {
+			tell application "System Events"
+				set frontmost of processes whose unix id is %d to true
+			end tell
+		} [pid] ]
+	}
+}
+
+
+######################################################################
+##
 ## Tcl/Tk sanity check
 
 if {[catch {package require Tcl 8.4} err]
-- 
1.8.3.14.g33f718c

```

## Stefan Haller, 2013-06-07 21:58

Subject: Re: [PATCH] git-gui: bring Wish process to front on Mac
Message-ID: <1l44d7u.14dslvlcdev12M%lists@haller-berlin.de>
URL: https://gitlist.dev/e/1l44d7u.14dslvlcdev12M%25lists%40haller-berlin.de
In-Reply-To: <7vk3m7yukc.fsf@alter.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> wrote:

> Stefan (as your name appears in 76bf6ff93e, I am assuming that you
> were the OSX-osascript guru in that commit) could you keep an eye on
> the list traffic to see if users of latest gitk have issues with
> that change, please?

Sure, will do.


-- 
Stefan Haller
Berlin, Germany
http://www.haller-berlin.de/

```

## Junio C Hamano, 2013-06-14 17:54

Subject: Re: [PATCH v2] git-gui: bring Wish process to front on Mac
Message-ID: <7vwqpwo9wd.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vwqpwo9wd.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1370642211-34416-1-git-send-email-stefan@haller-berlin.de>

```
Stefan Haller <stefan@haller-berlin.de> writes:

> On Mac OS X, any application that is started from the Terminal will open
> behind all running applications; as a work-around, manually bring ourselves
> to the front. (Stolen from gitk, commit 76bf6ff93e.)
>
> We do this as the very first thing, so that any message boxes that might pop
> up during the rest of the startup sequence are actually seen by the user.
>
> Signed-off-by: Stefan Haller <stefan@haller-berlin.de>
> ---

Pat, is there any progress on this?  I do not mind, and I actually
would prefer, a pull request early in the development cycle.

"I've been busy and haven't got around to it", is a perfectly
acceptable response.  Just pinging to check.

> Changes since the first patch: 
>  - add catch
>  - specify full path to /usr/bin/osascript
>
>  git-gui.sh | 15 +++++++++++++++
>  1 file changed, 15 insertions(+)
>
> diff --git a/git-gui.sh b/git-gui.sh
> index e133331..a792924 100755
> --- a/git-gui.sh
> +++ b/git-gui.sh
> @@ -29,6 +29,21 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA}]
>  
>  ######################################################################
>  ##
> +## On Mac, bring the current Wish process window to front
> +
> +if {[tk windowingsystem] eq "aqua"} {
> +	catch {
> +		exec /usr/bin/osascript -e [format {
> +			tell application "System Events"
> +				set frontmost of processes whose unix id is %d to true
> +			end tell
> +		} [pid] ]
> +	}
> +}
> +
> +
> +######################################################################
> +##
>  ## Tcl/Tk sanity check
>  
>  if {[catch {package require Tcl 8.4} err]

```

## Pat Thoyts, 2013-06-15 23:07

Subject: Re: [PATCH v2] git-gui: bring Wish process to front on Mac
Message-ID: <CABNJ2GL3zK9UqsQ-ZCVVkZwXEesjGnmuVbUeQfSKZhL6njm3BA@mail.gmail.com>
URL: https://gitlist.dev/e/CABNJ2GL3zK9UqsQ-ZCVVkZwXEesjGnmuVbUeQfSKZhL6njm3BA%40mail.gmail.com
In-Reply-To: <7vwqpwo9wd.fsf@alter.siamese.dyndns.org>

```
On 14 June 2013 18:54, Junio C Hamano <gitster@pobox.com> wrote:
> Stefan Haller <stefan@haller-berlin.de> writes:
>
>> On Mac OS X, any application that is started from the Terminal will open
>> behind all running applications; as a work-around, manually bring ourselves
>> to the front. (Stolen from gitk, commit 76bf6ff93e.)
>>
>> We do this as the very first thing, so that any message boxes that might pop
>> up during the rest of the startup sequence are actually seen by the user.
>>
>> Signed-off-by: Stefan Haller <stefan@haller-berlin.de>
>> ---
>
> Pat, is there any progress on this?  I do not mind, and I actually
> would prefer, a pull request early in the development cycle.
>

yep - I applied this and a couple of others and sent up a pull request
now. I see there are some commits in git's tree that I don't have on
this side so I'll merge those in here shortly.

```
