git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Gitk doesn't work on macOS Mojave
@ 2018-07-19 18:05 Evgeny Cherpak
  2018-07-19 19:12 ` Eric Sunshine
  0 siblings, 1 reply; 7+ messages in thread
From: Evgeny Cherpak @ 2018-07-19 18:05 UTC (permalink / raw)
  To: git

Hi

You have probably heard this by now already, but gitk doesn’t work on macOS 10.14 - because it uses Apple Events,
And apps on 10.14 require user to give them permissions to control other apps with Apple Events.

Here is what I get when I try running it on my machine with beta 4 installed:

Error in startup script: 58:102: execution error: Not authorized to send Apple events to System Events. (-1743)
    while executing
"exec osascript -e [format {
        tell application "System Events"
            set frontmost of processes whose unix id is %d to true
        end te..."
    invoked from within
"if {[tk windowingsystem] eq "aqua"} {
    exec osascript -e [format {
        tell application "System Events"
            set frontmost of processes ..."
    (file "/usr/local/bin/gitk" line 12212)

And Apple doesn’t allow to add apps to “Automation” :( 

Best regards.
And thanks for git :) 

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Gitk doesn't work on macOS Mojave
  2018-07-19 18:05 Gitk doesn't work on macOS Mojave Evgeny Cherpak
@ 2018-07-19 19:12 ` Eric Sunshine
  2018-07-19 21:11   ` Evgeny Cherpak
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Sunshine @ 2018-07-19 19:12 UTC (permalink / raw)
  To: cherpake; +Cc: Git List

On Thu, Jul 19, 2018 at 2:48 PM Evgeny Cherpak <cherpake@me.com> wrote:
> You have probably heard this by now already, but gitk doesn’t work on macOS 10.14 - because it uses Apple Events,
> And apps on 10.14 require user to give them permissions to control other apps with Apple Events.

This hasn't been reported, so thanks for bringing it up.

> Here is what I get when I try running it on my machine with beta 4 installed:
>
> Error in startup script: 58:102: execution error: Not authorized to send Apple events to System Events. (-1743)
>     while executing
> "exec osascript -e [format {
>         tell application "System Events"
>             set frontmost of processes whose unix id is %d to true
>         end te..."

Fortunately, this feature is merely a convenience, not otherwise
critical to gitk functioning. It would be ideal if someone running
Mojave could devise up a patch to work around the problem (either by
skipping this code on Mojave or discovering a different way to bring
the application to the foreground). An alternative would be to revert
76bf6ff93e (gitk: On OSX, bring the gitk window to front, 2013-04-24),
which introduced this code.

(Note, however, that the gitk project is dormant, so it's not clear if
such a patch will be picked up.)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Gitk doesn't work on macOS Mojave
  2018-07-19 19:12 ` Eric Sunshine
@ 2018-07-19 21:11   ` Evgeny Cherpak
  2018-07-19 21:49     ` Eric Sunshine
  0 siblings, 1 reply; 7+ messages in thread
From: Evgeny Cherpak @ 2018-07-19 21:11 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List

It seems this code placed at the end of the file, after getcommits() does the trick:

if {[tk windowingsystem] eq "aqua"} { 
	set openscript [format { 
		open -a \"$(ps -p %d -o comm=)\"
	} [pid] ]
    exec osascript -e [format {
		do shell script "%s"
    } "$openscript” ]
}


> On 19 Jul 2018, at 22:12, Eric Sunshine <sunshine@sunshineco.com> wrote:
> 
> On Thu, Jul 19, 2018 at 2:48 PM Evgeny Cherpak <cherpake@me.com> wrote:
>> You have probably heard this by now already, but gitk doesn’t work on macOS 10.14 - because it uses Apple Events,
>> And apps on 10.14 require user to give them permissions to control other apps with Apple Events.
> 
> This hasn't been reported, so thanks for bringing it up.
> 
>> Here is what I get when I try running it on my machine with beta 4 installed:
>> 
>> Error in startup script: 58:102: execution error: Not authorized to send Apple events to System Events. (-1743)
>>    while executing
>> "exec osascript -e [format {
>>        tell application "System Events"
>>            set frontmost of processes whose unix id is %d to true
>>        end te..."
> 
> Fortunately, this feature is merely a convenience, not otherwise
> critical to gitk functioning. It would be ideal if someone running
> Mojave could devise up a patch to work around the problem (either by
> skipping this code on Mojave or discovering a different way to bring
> the application to the foreground). An alternative would be to revert
> 76bf6ff93e (gitk: On OSX, bring the gitk window to front, 2013-04-24),
> which introduced this code.
> 
> (Note, however, that the gitk project is dormant, so it's not clear if
> such a patch will be picked up.)


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Gitk doesn't work on macOS Mojave
  2018-07-19 21:11   ` Evgeny Cherpak
@ 2018-07-19 21:49     ` Eric Sunshine
       [not found]       ` <BD1EAEBF-B125-4D3E-A814-F8824E5D2CA8@me.com>
  0 siblings, 1 reply; 7+ messages in thread
From: Eric Sunshine @ 2018-07-19 21:49 UTC (permalink / raw)
  To: cherpake; +Cc: Git List

[please reply inline rather than top-posting]

On Thu, Jul 19, 2018 at 5:11 PM Evgeny Cherpak <cherpake@me.com> wrote:
> It seems this code placed at the end of the file, after getcommits() does the trick:
>
> if {[tk windowingsystem] eq "aqua"} {
>         set openscript [format {
>                 open -a \"$(ps -p %d -o comm=)\"
>         } [pid] ]
>     exec osascript -e [format {
>                 do shell script "%s"
>     } "$openscript” ]
> }

Interesting idea. A shortcoming of this approach is that it's
non-deterministic. It will bring _any_ running gitk to the foreground,
rather than the one mentioned by PID, which would be a potentially
confusing regression. Such confusion _might_ be worse than simply not
foregrounding the application at all (though that's a matter of
opinion). Unfortunately, the 'open' command doesn't let you do so by
PID, and Googling shows only answers which predate Mojave (that is,
they all suggest Apple Events).

To avoid such a regression on older MacOS's, it would be nice to
retain the Apple Events code, but that would mean gitk would need to
do a version check or something to avoid executing the Apple Events
code on Mojave.

By the way, the same problem presumably afflicts "git gui", which has
identical code in it for foregrounding the application. Does that
match with your experience?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Gitk doesn't work on macOS Mojave
       [not found]               ` <C9089D48-5516-4EF9-9260-BADD62FA3CBD@me.com>
@ 2018-07-20  6:25                 ` Eric Sunshine
  2018-07-20  6:26                   ` Evgeny Cherpak
  2018-07-24  6:51                   ` [PATCH] gitk: fix MacOS 10.14 "Mojave" crash on launch Eric Sunshine
  0 siblings, 2 replies; 7+ messages in thread
From: Eric Sunshine @ 2018-07-20  6:25 UTC (permalink / raw)
  To: cherpake, Git List

[re-adding cc:git]

On Fri, Jul 20, 2018 at 12:38 AM Evgeny Cherpak <cherpake@me.com> wrote:
> > On 20 Jul 2018, at 7:30, Eric Sunshine <sunshine@sunshineco.com> wrote:
> >
> > On Fri, Jul 20, 2018 at 12:11 AM Evgeny Cherpak <cherpake@me.com> wrote:
> >> Not sure what you referring to?
> >> Is it alternative to gitk? How I install it?
> >
> > This: https://git-scm.com/docs/git-gui
> >
> > It's not an alternative to gitk, but complements it by providing
> > ability to stage and create commits, show blame information
> > graphically, etc.
> >
> > It's a standard part of the Git distribution, although it may not be
> > installed by default, depending upon your platform and the packager.
> > Some Linux distributions, for instance, may place it in a separate
> > package for installation (named "git-gui" or something).
>
> Just tried it - it works, but doesn't get focus.

Looking more closely, the code in "git gui" is catching and silently
ignoring errors:

    ## On Mac, bring the current Wish process window to front
    if {[tk windowingsystem] eq "aqua"} {
        catch {
            exec osascript -e [format {
                tell application "System Events"
                    set frontmost of processes whose unix id is %d to true
                end tell
            } [pid]]
        }
    }

which explains why you don't see the "Not authorized to send Apple
events" error you see with gitk, and also explains why the application
doesn't get focus.

So, updating gitk to mirror git-gui might be one way forward.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: Gitk doesn't work on macOS Mojave
  2018-07-20  6:25                 ` Eric Sunshine
@ 2018-07-20  6:26                   ` Evgeny Cherpak
  2018-07-24  6:51                   ` [PATCH] gitk: fix MacOS 10.14 "Mojave" crash on launch Eric Sunshine
  1 sibling, 0 replies; 7+ messages in thread
From: Evgeny Cherpak @ 2018-07-20  6:26 UTC (permalink / raw)
  To: Eric Sunshine; +Cc: Git List

👍

> On 20 Jul 2018, at 9:25, Eric Sunshine <sunshine@sunshineco.com> wrote:
> 
> [re-adding cc:git]
> 
> On Fri, Jul 20, 2018 at 12:38 AM Evgeny Cherpak <cherpake@me.com> wrote:
>>> On 20 Jul 2018, at 7:30, Eric Sunshine <sunshine@sunshineco.com> wrote:
>>> 
>>> On Fri, Jul 20, 2018 at 12:11 AM Evgeny Cherpak <cherpake@me.com> wrote:
>>>> Not sure what you referring to?
>>>> Is it alternative to gitk? How I install it?
>>> 
>>> This: https://git-scm.com/docs/git-gui
>>> 
>>> It's not an alternative to gitk, but complements it by providing
>>> ability to stage and create commits, show blame information
>>> graphically, etc.
>>> 
>>> It's a standard part of the Git distribution, although it may not be
>>> installed by default, depending upon your platform and the packager.
>>> Some Linux distributions, for instance, may place it in a separate
>>> package for installation (named "git-gui" or something).
>> 
>> Just tried it - it works, but doesn't get focus.
> 
> Looking more closely, the code in "git gui" is catching and silently
> ignoring errors:
> 
>    ## On Mac, bring the current Wish process window to front
>    if {[tk windowingsystem] eq "aqua"} {
>        catch {
>            exec osascript -e [format {
>                tell application "System Events"
>                    set frontmost of processes whose unix id is %d to true
>                end tell
>            } [pid]]
>        }
>    }
> 
> which explains why you don't see the "Not authorized to send Apple
> events" error you see with gitk, and also explains why the application
> doesn't get focus.
> 
> So, updating gitk to mirror git-gui might be one way forward.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH] gitk: fix MacOS 10.14 "Mojave" crash on launch
  2018-07-20  6:25                 ` Eric Sunshine
  2018-07-20  6:26                   ` Evgeny Cherpak
@ 2018-07-24  6:51                   ` Eric Sunshine
  1 sibling, 0 replies; 7+ messages in thread
From: Eric Sunshine @ 2018-07-24  6:51 UTC (permalink / raw)
  To: git; +Cc: Paul Mackerras, Evgeny Cherpak, Eric Sunshine

On MacOS, a "wish" application started from the terminal opens in the
background, thus doesn't match user expectation that a newly-launched
application ought to be placed in the foreground. To address this
shortcoming, both gitk and git-gui use Apple Events to send a message to
"System Events" instructing it to foreground the "wish" application by
PID.

Unfortunately, MacOS 10.14 tightens restrictions on Apple Events,
requiring explicit granting of permission to control applications in
this fashion, and apparently such granting for "Automation" is not
allowed at all[1]. As a consequence gitk crashes outright at launch time
with a "Not authorized to send Apple events to System Events" error,
thus is entirely unusable on "Mojave".

In contrast, git-gui does not crash since it deliberately[2] catches and
ignores Apple Events errors. This does mean that git-gui will not
automatically become the foreground application on "Mojave", which is a
minor inconvenience but far better than crashing outright as gitk does.

Update gitk to catch and ignore Apple Events errors, mirroring git-gui's
behavior, to avoid this crash.

(Finding and implementing an alternate approach to foregrounding the
"wish" application on "Mojave" may be desirable but is outside the scope
of this crash fix.)

[1]: https://public-inbox.org/git/D295145E-7596-4409-9681-D8ADBB9EBB0C@me.com/
[2]: https://public-inbox.org/git/CABNJ2G+h3zh+=wLA0KHjUn8TsfhqUK1Kn-1_=6hnXVRJUPhuuA@mail.gmail.com/

Reported-by: Evgeny Cherpak <cherpake@me.com>
Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---

Lack of 'catch' in the 'osascript' invocation in gitk was recognized as
a potential problem as far back as June 2013 [3,4]; now it's biting
"Mojave" users, making gitk unusable.

[3]: https://public-inbox.org/git/7vk3m7yukc.fsf@alter.siamese.dyndns.org/
[4]: https://public-inbox.org/git/1l424u5.uk987q18u3oxfM%25lists@haller-berlin.de/

 gitk-git/gitk | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/gitk-git/gitk b/gitk-git/gitk
index a14d7a16b2..f13d1807bb 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -12210,11 +12210,13 @@ if {[catch {package require Tk 8.4} err]} {
 
 # on OSX 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] ]
+    catch {
+	exec osascript -e [format {
+	    tell application "System Events"
+		set frontmost of processes whose unix id is %d to true
+	    end tell
+	} [pid] ]
+    }
 }
 
 # Unset GIT_TRACE var if set
-- 
2.18.0.345.g5c9ce644c3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2018-07-24  6:51 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-19 18:05 Gitk doesn't work on macOS Mojave Evgeny Cherpak
2018-07-19 19:12 ` Eric Sunshine
2018-07-19 21:11   ` Evgeny Cherpak
2018-07-19 21:49     ` Eric Sunshine
     [not found]       ` <BD1EAEBF-B125-4D3E-A814-F8824E5D2CA8@me.com>
     [not found]         ` <CAPig+cTRdh56VVcOGzeJmUN-L0-v2i+rCdMGxdr1FEUgfUGw4g@mail.gmail.com>
     [not found]           ` <5196A9EF-3967-4E4A-A929-58CD8BE72150@me.com>
     [not found]             ` <CAPig+cRDTMW5O1T20CnK03wWb9W8ev9q34U4P4rRk-3hrnNfGg@mail.gmail.com>
     [not found]               ` <C9089D48-5516-4EF9-9260-BADD62FA3CBD@me.com>
2018-07-20  6:25                 ` Eric Sunshine
2018-07-20  6:26                   ` Evgeny Cherpak
2018-07-24  6:51                   ` [PATCH] gitk: fix MacOS 10.14 "Mojave" crash on launch Eric Sunshine

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).