{"id":651,"date":"2020-05-01T11:47:39","date_gmt":"2020-05-01T10:47:39","guid":{"rendered":"http:\/\/www.renaudpradenc.com\/?p=651"},"modified":"2020-05-01T13:23:28","modified_gmt":"2020-05-01T12:23:28","slug":"trying-to-make-the-touchbar-useful","status":"publish","type":"post","link":"https:\/\/www.renaudpradenc.com\/?p=651","title":{"rendered":"Trying to make the TouchBar useful"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u2026 for a French Coder.<\/h2>\n\n\n\n<p>I know a number of fellow French programmers who always order their new Macs with an English keyboard, despite it being unadapted to the French language. French AZERTY keyboards are inconvenient for programming:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>one must press the Shift key to type digits<\/li><li>typing some characters is awkward, e.g. pressing Option-Shift-( to type a [.<\/li><li>By default, text editors have keyboard shortcuts that can not even be typed. I have customized Xcode&#8217;s shortcuts for this reason.<\/li><\/ul>\n\n\n\n<p>I thought I could use the TouchBar to provide me extra keys!<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How to customize the TouchBar<\/h2>\n\n\n\n<p>You basically have two choices:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><a href=\"https:\/\/folivora.ai\">BetterTouchTool<\/a> is the most obvious option. I haven&#8217;t actually tried it, but it&#8217;s cheap (about 10 \u20ac) and there&#8217;s a 45-day trial.<\/li><li><a href=\"https:\/\/mtmr.app\">MTMR<\/a> is free and open-source. I chose it because I wanted to study how it worked under the cover. The app is not notarized for Catalina and still needs refinements, but it works.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">The MTMR preset<\/h3>\n\n\n\n<p>You may download it now: <a href=\"https:\/\/gist.github.com\/Ceroce\/f5efb0a7f24a23ac1a67a4d73618dce3\">FrenchProgrammer.json<\/a> and skip the explanations.<\/p>\n\n\n\n<p>I actually had to study the source code to write the Preset. The documentation is unclear, but there is actually a problem with the manner to simulate key presses on macOS, since you have to provide a &#8220;keycode&#8221;:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n\t\"title\": \"2\",\n\t\"type\": \"staticButton\",\n\t\"action\": \"keyPress\",\n\t\"keycode\": 84, \/\/ 0x54 is Keypad '2'\n\t\"width\": 81\n},<\/code><\/pre>\n\n\n\n<p>You may find a list of keycodes <a href=\"https:\/\/gist.github.com\/eegrok\/949034\">here<\/a>, or in Events.h of the HIToolbox framework. These codes are given for an American keyboard. For instance, it means that using the keycode 0x00 will type an &#8216;A&#8217; on an American keyboard but a &#8216;Q&#8217; on a French keyboard, because keycodes map to locations of keys, not characters. <\/p>\n\n\n\n<p>The second problem is that MTMR currently does not offer a mean to provide key-modifiers along with the keycode, so I cannot simulate directly typing a Option-Shift-( to type a [.<\/p>\n\n\n\n<p>There is however a solution: use AppleScript!<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n\t\"title\": \"&#91;\",\n\t\"type\": \"staticButton\",\n\t\"action\": \"appleScript\",\n\t\"actionAppleScript\": {\n  \t\t\"inline\": \"tell application \\\"System Events\\\" to keystroke \\\"(\\\" using {option down, shift down}\\r\"\n\t},\n\t\"width\": 81\n},<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Time to test<\/h2>\n\n\n\n<p>I don&#8217;t know whether I am gonna keep this configuration but I should try it a couple of weeks to see if I get used to it.<\/p>\n\n\n\n<p>I might also change my layout. Pressing Shift to type digits is not too much of an issue and I could propose other characters, or <a href=\"https:\/\/www.alfredapp.com\">Alfred<\/a> actions instead.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u2026 for a French Coder. I know a number of fellow French programmers who always order their new Macs with an English keyboard, despite it being unadapted to the French language. French AZERTY keyboards are inconvenient for programming: one must press the Shift key to type digits typing some characters is awkward, e.g. pressing Option-Shift-( [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":652,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[89],"tags":[],"class_list":["post-651","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-english"],"_links":{"self":[{"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/posts\/651","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=651"}],"version-history":[{"count":6,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/posts\/651\/revisions"}],"predecessor-version":[{"id":658,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/posts\/651\/revisions\/658"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=\/wp\/v2\/media\/652"}],"wp:attachment":[{"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=651"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=651"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.renaudpradenc.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=651"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}