{"thread":{"id":"48920","subject":"Gitk doesn't work on macOS Mojave","startedAt":"2018-07-19T18:48:41Z","lastAt":"2018-07-24T06:51:56Z","messageCount":7,"participants":["Evgeny Cherpak","Eric Sunshine"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"353059","messageId":"D295145E-7596-4409-9681-D8ADBB9EBB0C@me.com","threadId":"48920","inReplyTo":null,"subject":"Gitk doesn't work on macOS Mojave","fromName":"Evgeny Cherpak","fromEmail":"cherpake@me.com","sentAt":"2018-07-19T18:05:43Z","receivedAt":"2018-07-19T18:48:41Z","isPatch":false,"sender":{"key":"cherpake@me.com","avatar":null},"body":"Hi\n\nYou have probably heard this by now already, but gitk doesn’t work on macOS 10.14 - because it uses Apple Events,\nAnd apps on 10.14 require user to give them permissions to control other apps with Apple Events.\n\nHere is what I get when I try running it on my machine with beta 4 installed:\n\nError in startup script: 58:102: execution error: Not authorized to send Apple events to System Events. (-1743)\n    while executing\n\"exec osascript -e [format {\n        tell application \"System Events\"\n            set frontmost of processes whose unix id is %d to true\n        end te...\"\n    invoked from within\n\"if {[tk windowingsystem] eq \"aqua\"} {\n    exec osascript -e [format {\n        tell application \"System Events\"\n            set frontmost of processes ...\"\n    (file \"/usr/local/bin/gitk\" line 12212)\n\nAnd Apple doesn’t allow to add apps to “Automation” :( \n\nBest regards.\nAnd thanks for git :) "},{"id":"353069","messageId":"CAPig+cT+Z-hN6WidMOUW2jRVNFovvv03LEFESXpr05NKmpnWAA@mail.gmail.com","threadId":"48920","inReplyTo":"D295145E-7596-4409-9681-D8ADBB9EBB0C@me.com","subject":"Re: Gitk doesn't work on macOS Mojave","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-07-19T19:12:58Z","receivedAt":"2018-07-19T19:13:12Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Thu, Jul 19, 2018 at 2:48 PM Evgeny Cherpak <cherpake@me.com> wrote:\n> You have probably heard this by now already, but gitk doesn’t work on macOS 10.14 - because it uses Apple Events,\n> And apps on 10.14 require user to give them permissions to control other apps with Apple Events.\n\nThis hasn't been reported, so thanks for bringing it up.\n\n> Here is what I get when I try running it on my machine with beta 4 installed:\n>\n> Error in startup script: 58:102: execution error: Not authorized to send Apple events to System Events. (-1743)\n>     while executing\n> \"exec osascript -e [format {\n>         tell application \"System Events\"\n>             set frontmost of processes whose unix id is %d to true\n>         end te...\"\n\nFortunately, this feature is merely a convenience, not otherwise\ncritical to gitk functioning. It would be ideal if someone running\nMojave could devise up a patch to work around the problem (either by\nskipping this code on Mojave or discovering a different way to bring\nthe application to the foreground). An alternative would be to revert\n76bf6ff93e (gitk: On OSX, bring the gitk window to front, 2013-04-24),\nwhich introduced this code.\n\n(Note, however, that the gitk project is dormant, so it's not clear if\nsuch a patch will be picked up.)\n"},{"id":"353080","messageId":"1569C0A9-7C44-4F28-9C9B-AF2489E021AB@me.com","threadId":"48920","inReplyTo":"CAPig+cT+Z-hN6WidMOUW2jRVNFovvv03LEFESXpr05NKmpnWAA@mail.gmail.com","subject":"Re: Gitk doesn't work on macOS Mojave","fromName":"Evgeny Cherpak","fromEmail":"cherpake@me.com","sentAt":"2018-07-19T21:11:13Z","receivedAt":"2018-07-19T21:11:18Z","isPatch":false,"sender":{"key":"cherpake@me.com","avatar":null},"body":"It seems this code placed at the end of the file, after getcommits() does the trick:\n\nif {[tk windowingsystem] eq \"aqua\"} { \n\tset openscript [format { \n\t\topen -a \\\"$(ps -p %d -o comm=)\\\"\n\t} [pid] ]\n    exec osascript -e [format {\n\t\tdo shell script \"%s\"\n    } \"$openscript” ]\n}\n\n\n> On 19 Jul 2018, at 22:12, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> \n> On Thu, Jul 19, 2018 at 2:48 PM Evgeny Cherpak <cherpake@me.com> wrote:\n>> You have probably heard this by now already, but gitk doesn’t work on macOS 10.14 - because it uses Apple Events,\n>> And apps on 10.14 require user to give them permissions to control other apps with Apple Events.\n> \n> This hasn't been reported, so thanks for bringing it up.\n> \n>> Here is what I get when I try running it on my machine with beta 4 installed:\n>> \n>> Error in startup script: 58:102: execution error: Not authorized to send Apple events to System Events. (-1743)\n>>    while executing\n>> \"exec osascript -e [format {\n>>        tell application \"System Events\"\n>>            set frontmost of processes whose unix id is %d to true\n>>        end te...\"\n> \n> Fortunately, this feature is merely a convenience, not otherwise\n> critical to gitk functioning. It would be ideal if someone running\n> Mojave could devise up a patch to work around the problem (either by\n> skipping this code on Mojave or discovering a different way to bring\n> the application to the foreground). An alternative would be to revert\n> 76bf6ff93e (gitk: On OSX, bring the gitk window to front, 2013-04-24),\n> which introduced this code.\n> \n> (Note, however, that the gitk project is dormant, so it's not clear if\n> such a patch will be picked up.)\n\n"},{"id":"353091","messageId":"CAPig+cRYVwsMxUQGWHWyfC1gpVgEtt0VH-CmQoGizEAp-B_7WQ@mail.gmail.com","threadId":"48920","inReplyTo":"1569C0A9-7C44-4F28-9C9B-AF2489E021AB@me.com","subject":"Re: Gitk doesn't work on macOS Mojave","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-07-19T21:49:17Z","receivedAt":"2018-07-19T21:49:31Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"[please reply inline rather than top-posting]\n\nOn Thu, Jul 19, 2018 at 5:11 PM Evgeny Cherpak <cherpake@me.com> wrote:\n> It seems this code placed at the end of the file, after getcommits() does the trick:\n>\n> if {[tk windowingsystem] eq \"aqua\"} {\n>         set openscript [format {\n>                 open -a \\\"$(ps -p %d -o comm=)\\\"\n>         } [pid] ]\n>     exec osascript -e [format {\n>                 do shell script \"%s\"\n>     } \"$openscript” ]\n> }\n\nInteresting idea. A shortcoming of this approach is that it's\nnon-deterministic. It will bring _any_ running gitk to the foreground,\nrather than the one mentioned by PID, which would be a potentially\nconfusing regression. Such confusion _might_ be worse than simply not\nforegrounding the application at all (though that's a matter of\nopinion). Unfortunately, the 'open' command doesn't let you do so by\nPID, and Googling shows only answers which predate Mojave (that is,\nthey all suggest Apple Events).\n\nTo avoid such a regression on older MacOS's, it would be nice to\nretain the Apple Events code, but that would mean gitk would need to\ndo a version check or something to avoid executing the Apple Events\ncode on Mojave.\n\nBy the way, the same problem presumably afflicts \"git gui\", which has\nidentical code in it for foregrounding the application. Does that\nmatch with your experience?\n"},{"id":"353114","messageId":"CAPig+cTJvJLMe4CFOb-yxqwF4udvs4G-BUiT=Kp-NZcfAWAyiQ@mail.gmail.com","threadId":"48920","inReplyTo":"C9089D48-5516-4EF9-9260-BADD62FA3CBD@me.com","subject":"Re: Gitk doesn't work on macOS Mojave","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-07-20T06:25:32Z","receivedAt":"2018-07-20T06:25:45Z","isPatch":false,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"[re-adding cc:git]\n\nOn Fri, Jul 20, 2018 at 12:38 AM Evgeny Cherpak <cherpake@me.com> wrote:\n> > On 20 Jul 2018, at 7:30, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> >\n> > On Fri, Jul 20, 2018 at 12:11 AM Evgeny Cherpak <cherpake@me.com> wrote:\n> >> Not sure what you referring to?\n> >> Is it alternative to gitk? How I install it?\n> >\n> > This: https://git-scm.com/docs/git-gui\n> >\n> > It's not an alternative to gitk, but complements it by providing\n> > ability to stage and create commits, show blame information\n> > graphically, etc.\n> >\n> > It's a standard part of the Git distribution, although it may not be\n> > installed by default, depending upon your platform and the packager.\n> > Some Linux distributions, for instance, may place it in a separate\n> > package for installation (named \"git-gui\" or something).\n>\n> Just tried it - it works, but doesn't get focus.\n\nLooking more closely, the code in \"git gui\" is catching and silently\nignoring errors:\n\n    ## On Mac, bring the current Wish process window to front\n    if {[tk windowingsystem] eq \"aqua\"} {\n        catch {\n            exec osascript -e [format {\n                tell application \"System Events\"\n                    set frontmost of processes whose unix id is %d to true\n                end tell\n            } [pid]]\n        }\n    }\n\nwhich explains why you don't see the \"Not authorized to send Apple\nevents\" error you see with gitk, and also explains why the application\ndoesn't get focus.\n\nSo, updating gitk to mirror git-gui might be one way forward.\n"},{"id":"353115","messageId":"CC28BF55-9334-42A8-8A40-5D3E54BF8961@me.com","threadId":"48920","inReplyTo":"CAPig+cTJvJLMe4CFOb-yxqwF4udvs4G-BUiT=Kp-NZcfAWAyiQ@mail.gmail.com","subject":"Re: Gitk doesn't work on macOS Mojave","fromName":"Evgeny Cherpak","fromEmail":"cherpake@me.com","sentAt":"2018-07-20T06:26:55Z","receivedAt":"2018-07-20T06:27:01Z","isPatch":false,"sender":{"key":"cherpake@me.com","avatar":null},"body":"👍\n\n> On 20 Jul 2018, at 9:25, Eric Sunshine <sunshine@sunshineco.com> wrote:\n> \n> [re-adding cc:git]\n> \n> On Fri, Jul 20, 2018 at 12:38 AM Evgeny Cherpak <cherpake@me.com> wrote:\n>>> On 20 Jul 2018, at 7:30, Eric Sunshine <sunshine@sunshineco.com> wrote:\n>>> \n>>> On Fri, Jul 20, 2018 at 12:11 AM Evgeny Cherpak <cherpake@me.com> wrote:\n>>>> Not sure what you referring to?\n>>>> Is it alternative to gitk? How I install it?\n>>> \n>>> This: https://git-scm.com/docs/git-gui\n>>> \n>>> It's not an alternative to gitk, but complements it by providing\n>>> ability to stage and create commits, show blame information\n>>> graphically, etc.\n>>> \n>>> It's a standard part of the Git distribution, although it may not be\n>>> installed by default, depending upon your platform and the packager.\n>>> Some Linux distributions, for instance, may place it in a separate\n>>> package for installation (named \"git-gui\" or something).\n>> \n>> Just tried it - it works, but doesn't get focus.\n> \n> Looking more closely, the code in \"git gui\" is catching and silently\n> ignoring errors:\n> \n>    ## On Mac, bring the current Wish process window to front\n>    if {[tk windowingsystem] eq \"aqua\"} {\n>        catch {\n>            exec osascript -e [format {\n>                tell application \"System Events\"\n>                    set frontmost of processes whose unix id is %d to true\n>                end tell\n>            } [pid]]\n>        }\n>    }\n> \n> which explains why you don't see the \"Not authorized to send Apple\n> events\" error you see with gitk, and also explains why the application\n> doesn't get focus.\n> \n> So, updating gitk to mirror git-gui might be one way forward.\n\n"},{"id":"353445","messageId":"20180724065120.7664-1-sunshine@sunshineco.com","threadId":"48920","inReplyTo":"CAPig+cTJvJLMe4CFOb-yxqwF4udvs4G-BUiT=Kp-NZcfAWAyiQ@mail.gmail.com","subject":"[PATCH] gitk: fix MacOS 10.14 \"Mojave\" crash on launch","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-07-24T06:51:20Z","receivedAt":"2018-07-24T06:51:56Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On MacOS, a \"wish\" application started from the terminal opens in the\nbackground, thus doesn't match user expectation that a newly-launched\napplication ought to be placed in the foreground. To address this\nshortcoming, both gitk and git-gui use Apple Events to send a message to\n\"System Events\" instructing it to foreground the \"wish\" application by\nPID.\n\nUnfortunately, MacOS 10.14 tightens restrictions on Apple Events,\nrequiring explicit granting of permission to control applications in\nthis fashion, and apparently such granting for \"Automation\" is not\nallowed at all[1]. As a consequence gitk crashes outright at launch time\nwith a \"Not authorized to send Apple events to System Events\" error,\nthus is entirely unusable on \"Mojave\".\n\nIn contrast, git-gui does not crash since it deliberately[2] catches and\nignores Apple Events errors. This does mean that git-gui will not\nautomatically become the foreground application on \"Mojave\", which is a\nminor inconvenience but far better than crashing outright as gitk does.\n\nUpdate gitk to catch and ignore Apple Events errors, mirroring git-gui's\nbehavior, to avoid this crash.\n\n(Finding and implementing an alternate approach to foregrounding the\n\"wish\" application on \"Mojave\" may be desirable but is outside the scope\nof this crash fix.)\n\n[1]: https://public-inbox.org/git/D295145E-7596-4409-9681-D8ADBB9EBB0C@me.com/\n[2]: https://public-inbox.org/git/CABNJ2G+h3zh+=wLA0KHjUn8TsfhqUK1Kn-1_=6hnXVRJUPhuuA@mail.gmail.com/\n\nReported-by: Evgeny Cherpak <cherpake@me.com>\nSigned-off-by: Eric Sunshine <sunshine@sunshineco.com>\n---\n\nLack of 'catch' in the 'osascript' invocation in gitk was recognized as\na potential problem as far back as June 2013 [3,4]; now it's biting\n\"Mojave\" users, making gitk unusable.\n\n[3]: https://public-inbox.org/git/7vk3m7yukc.fsf@alter.siamese.dyndns.org/\n[4]: https://public-inbox.org/git/1l424u5.uk987q18u3oxfM%25lists@haller-berlin.de/\n\n gitk-git/gitk | 12 +++++++-----\n 1 file changed, 7 insertions(+), 5 deletions(-)\n\ndiff --git a/gitk-git/gitk b/gitk-git/gitk\nindex a14d7a16b2..f13d1807bb 100755\n--- a/gitk-git/gitk\n+++ b/gitk-git/gitk\n@@ -12210,11 +12210,13 @@ if {[catch {package require Tk 8.4} err]} {\n \n # on OSX bring the current Wish process window to front\n if {[tk windowingsystem] eq \"aqua\"} {\n-    exec osascript -e [format {\n-        tell application \"System Events\"\n-            set frontmost of processes whose unix id is %d to true\n-        end tell\n-    } [pid] ]\n+    catch {\n+\texec osascript -e [format {\n+\t    tell application \"System Events\"\n+\t\tset frontmost of processes whose unix id is %d to true\n+\t    end tell\n+\t} [pid] ]\n+    }\n }\n \n # Unset GIT_TRACE var if set\n-- \n2.18.0.345.g5c9ce644c3\n\n"}]}