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

Subsystems: the rest

STALE3737d

4 messages, 3 authors, 2016-06-15 · open the first message on its own page

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

From: Stefan Haller <hidden>
Date: 2016-06-15 22:57:34

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 <redacted>
---
 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

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

From: Pat Thoyts <hidden>
Date: 2016-06-15 22:57:34

On 6 June 2013 09:17, Stefan Haller [off-list ref] wrote:
quoted hunk
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 <redacted>
---
 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.

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

From: Stefan Haller <hidden>
Date: 2016-06-15 22:57:34

Pat Thoyts [off-list ref] wrote:
On 6 June 2013 09:17, Stefan Haller [off-list ref] wrote:
quoted
+## 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/

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

From: Stefan Haller <hidden>
Date: 2016-06-15 22:57:35

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 <redacted>
---
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help