Swiftpack.co - Package - Toxblh/MTMR

My touchbar. My rules. GitHub release license minimal system requirements travis

The TouchBar Customization App for your MacBook Pro

My idea is to create a platform for creating plugins to customize the TouchBar. I very much like BTT and having a full custom TouchBar (my BTT preset), and I wanted to create it. It's my first Swift project for MacOS :)

Share your presets here

Mackbook with touchbar

Discord Telegram

PayPal donate button Buy Me A Coffee My TouchBar My Rules (MTMR)

Installation

On first install you need to allow access for MTMR in Accessibility otherwise buttons like Esc, Volume, Brightness and other system keys won't work

screenshot 2019-02-24 at 23 19 20

🍏→ System Preferences → Security and Privacy → tab Privacy → Accessibility → MTMR

Examples

MTMR presets

Presets for touchbar

Customization

MTMR preferences are stored under ~/Library/Application\ Support/MTMR/items.json.

The pre-installed configuration contains less or more than you'll probably want, try to configure:

Built-in button types:

Buttons

  • escape
  • exitTouchbar
  • brightnessUp
  • brightnessDown
  • illuminationUp (keyboard illumination)
  • illuminationDown (keyboard illumination)
  • volumeDown
  • volumeUp
  • mute

Native Plugins

  • timeButton
  • battery
  • currency
  • weather
  • yandexWeather
  • inputsource
  • music (tap for pause, longTap for next)
  • dock (half-long click to open app, full-long click to kill app)
  • nightShift
  • dnd (Don't disturb)
  • darkMode
  • pomodoro
  • network

Media Keys

  • previous
  • play
  • next

AppleScript plugins

  • sleep
  • displaySleep

Custom buttons

  • staticButton
  • appleScriptTitledButton
  • shellScriptTitledButton

Gestures

By default you can enable basic gestures from application menu (status bar -> MTMR icon -> Volume/Brightness gestures):

  • two finger slide: change you Volume
  • three finger slide: change you Brightness

Custom gestures

You can add custom actions for two/three/four finger swipes. To do it, you need to use swipe type:

    "type": "swipe",
    "fingers": 2,            // number of fingers required (2,3 or 4)
    "direction": "right",    // direction of swipe (right/left)
    "minOffset" 10,          // optional: minimal required offset for gesture to emit event
    "sourceApple": {         // optional: apple script to run
        "inline": "beep"
    },
    "sourceBash": {          // optional: bash script to run
        "inline": "touch /Users/lobster/test"
    }

You may create as many swipe objects in the preset as you want.

Built-in slider types:

  • brightness
  • volume

You can also make custom buttons using these types

staticButton

 "type": "staticButton",
 "title": "esc",

appleScriptTitledButton

  {
    "type": "appleScriptTitledButton",
    "refreshInterval": 60, //optional
    "source": {
      "filePath": "~/Library/Application Support/MTMR/iTunes.nowPlaying.scpt",
      // or
      "inline": "tell application \"Finder\"\rif not (exists window 1) then\rmake new Finder window\rset target of front window to path to home folder as string\rend if\ractivate\rend tell",
      // or
      "base64": "StringInbase64"
    },
  }

Note: appleScriptTitledButton can change its icon. To do it, you need to do the following things:

  1. Declarate dictionary of icons in alternativeImages field
  2. Make you script return array of two values - {"TITLE", "IMAGE_LABEL"}
  3. Make sure that your IMAGE_LABEL is declared in alternativeImages field

Example:

  {
    "type": "appleScriptTitledButton",
    "source": {
      "inline": "if (random number from 1 to 2) = 1 then\n\tset val to {\"title\", \"play\"}\nelse\n\tset val to {\"title\", \"pause\"}\nend if\nreturn val"
    },
    "refreshInterval": 1,
    "image": {
      "base64": "iVBORw0KGgoAAAANSUhEUgA..."
    },
    "alternativeImages": {
      "play": {
        "base64": "iVBORw0KGgoAAAANSUhEUgAAAAAA..."
      },
      "pause": {
        "base64": "iVBORw0KGgoAAAANSUhEUgAAAIAA..."
      }
    }
  },

shellScriptTitledButton

Note: script may return also colors using escape sequences (read more here https://misc.flogisoft.com/bash/tip_colors_and_formatting) Only "16 Colors" mode supported atm. If background color returned, button will pick it up as own background color.

Example of "CPU load" button which also changes color based on load value.

{
  "type": "shellScriptTitledButton",
  "width": 80,
  "refreshInterval": 2,
  "source": {
    "inline": "top -l 2 -n 0 -F | egrep -o ' \\d*\\.\\d+% idle' | tail -1 | awk -F% '{p = 100 - $1; if (p > 30) c = \"\\033[33m\"; if (p > 70) c = \"\\033[30;43m\"; printf \"%s%4.1f%%\\n\", c, p}'"
  },
  "action": "appleScript",
  "actionAppleScript": {
    "inline": "activate application \"Activity Monitor\"\rtell application \"System Events\"\r\ttell process \"Activity Monitor\"\r\t\ttell radio button \"CPU\" of radio group 1 of group 2 of toolbar 1 of window 1 to perform action \"AXPress\"\r\tend tell\rend tell"
  },
  "align": "right",
  "image": {
    // Or you can specify a filePath here.
    // Images will be resized to 24x24.
    // "filePath": "~/myproject/myimage.jpg" // or "/fixed/path/to/the.png"
    "base64":
    "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA/1BMVEUAAADaACbYACfYACfjABzXACjYACfXACjYACfYACfYACfYACfdACLYACfXACjYACfVACv/AADXACjYACfYACfXACjYACfXACjaACXYACfYACfVACvYACfYACfZACbZACbYACfYACfZACb/AADYACfYACfVACrXACjVACu/AEDYACfYACfYACfXACjXACjYACfXACjYACfYACfYACfXACjYACfXACjYACfYACfZACbYACfYACfMADPYACfYACfYACfYACfYACfZACbXACjYACfYACfRAC7XACjYACfZACbWACnXACjXACjYACfTACzZACb/AADYACfYACfYACcAAAA+zneGAAAAU3RSTlMAItK+CVPjh3xUxPwPiGDQGAMtSKmN3Vk+wPQG/e26oIJBnwJCdiuAHgTmw+6BX+IgfaqLUvKOW8VKnagK+vBwYrhlc/urCznvhSyUbOEXPAFjGh/ektAAAAABYktHRACIBR1IAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4ggWETQWgEDcSgAAAqVJREFUWMPtl4ly2jAQhsUNNlcw5r4SICEHLSQhCQRyX73T/u//LpUlLIyxbMAznWmn/0ywo5U+27tr7ZoQuwLBUJidRKIxPhKLRtgxHAoGiLfiQIKdKFCTxjGpQmEDCSC+BiAFpNlJBsgaxyyQYQNpIPUf8AcAOzktD+iaoQJQNI5FoMAGdCCv5XZclpfKFXiqUi5Jllf1mvdyQzW96gigd4h6o+mhRp1O0x3vvwa1VSWeqrZU1Jyeogy01ggSVQsoO/i/gjq9/u6u+2LDXq2jshqLHNCgdsCVwO0NILdi0oDmuoAmoImhQDzFRPNnb36L7U43NVfc2EH2D9h5t9OePyIF5IU9uIhvkyN7iiXmQUIOj8x/lB6f0bTaQ3ZA+9iaNCH2Lpg6btsBIRJOpJl0E9ABTvof5kqEGeCjMaN/AnRMgM5XJcI2J1J1gf6S48Tb2Ae6JkAjdgmAeJ1XAOJ1Xg8wGJ6elXwAzkeGjy62BgxG3MuXnoCIkmEq8EQyAUPgajyhPxJAga9SIiRqzwMOuAbGZDrDjQRgKkpiqiPgFphM74B7d4BKy2cyy1RcBvSodUb/HiSAIl+VlEfh8cm4wvPL9nnw+gbc+kkkUVioO95etwe8PBuP8vQoBzg7UQAe5t7syZwoCaMA3AN30wlzh3MYJYkkADeYTckYuJYlkiSVBeCKZtSY/gxlqezlxEt+pdFg6zBesPXn1ih8Aj5vkAels9PhYCkPsl++kg0AQu4dyuqmugIQm+qS5Nv6N+D7wm7d1skPc4xu666Fhd6BxU6r+jub8tNaWNxK29EhsdpR/sVn7FlLm0txPdgni+JrFNd3p+K67MQtyrsp3w2G7xbHd5Plv83z3Wj6b3V9N9ssFv7afaa//ZPn3wD4/vje8PP/N7TebS0hgZhEAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDE4LTA4LTIyVDE3OjUyOjIyKzAyOjAwc2qUYAAAACV0RVh0ZGF0ZTptb2RpZnkAMjAxOC0wOC0yMlQxNzo1MjoyMiswMjowMAI3LNwAAAAZdEVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAAElFTkSuQmCC"
  },
  "bordered": false
}

Groups

{
  "type": "group",
  "align": "center",
  "bordered": true,
  "title": "stats",
  "items": [
    { "type": "play" },
    { "type": "mute" },
    ...
  ]
}

To close a group, use the button:

{
  "type": "close",
  "width": 64
},

Native plugins

timeButton

Attention! Works not all: https://en.wikipedia.org/wiki/List_of_time_zone_abbreviations

formatTemplate examples: https://www.datetimeformatter.com/how-to-format-date-time-in-swift/

locale examples: https://gist.github.com/jacobbubu/1836273

{
  "type": "timeButton",
  "formatTemplate": "dd HH:mm",
  "locale": "en_GB",
  "timeZone": "UTC"
}

weather

Provider: https://openweathermap.org
Note: you need to register on https://openweathermap.org to get your API key
Note: you may need to wait for near 20 mins until your API key will be activated by Openweathermap
Note: you need to allow using "Location Services" in your Mac OS "Security & Privacy" settings for MTMR

  "type": "weather",
  "refreshInterval": 600, // in seconds
  "units": "metric", // or imperial
  "icon_type": "text" // or images
  "api_key": "" // you can get the key on openweather

yandexWeather (experimental)

Provider: https://yandex.ru/pogoda. One click to open up weather forecast in your browser.
Note: you need to allow using "Location Services" in your Mac OS "Security & Privacy" settings for MTMR

  "type": "yandexWeather",
  "refreshInterval": 600 // in seconds

currency

Provider: https://coinbase.com

  "type": "currency",
  "refreshInterval": 600, // in seconds
  "align": "right",
  "from": "BTC",
  "to": "USD",
  "full": true // £‣1.29$

music

{
  "type": "music",
  "align": "center",
  "width": 80, // Optional
  "bordered": false, // Optional
  "refreshInterval": 2, // in seconds. Optional. Default 5 seconds
  "disableMarquee": true // to disable marquee effect. Optional. Default false
},

pomodoro

Pomodoro plugin. One click to start the work timer, longclick to start the rest timer. Click in progress for reset.

{
  "type": "pomodoro",
  "workTime": 1200, // set time work in seconds. Default 1500 (25 min)
  "restTime": 600 // set time rest in seconds. Default 300 (5 min)
},

network

Network plugin. The plugin to show usage a network

{
  "type": "network",
  "flip": true
},

dock

Dock plugin

{
  "type": "dock",
  "filter": "(^Xcode$)|(Safari)|(.*player)",
  "autoResize": true
},

Actions:

  • hidKey

    https://github.com/aosm/IOHIDFamily/blob/master/IOHIDSystem/IOKit/hidsystem/ev_keymap.h use only numbers

 "action": "hidKey",
 "keycode": 53,
  • keyPress
 "action": "keyPress",
 "keycode": 1,
  • appleScript
 "action": "appleScript",
 "actionAppleScript": {
      "inline": "tell application \"Finder\"\rif not (exists window 1) then\rmake new Finder window\rset target of front window to path to home folder as string\rend if\ractivate\rend tell",
    // "filePath" or "base64" will work as well
 },
  • shellScript
 "action": "shellScript",
 "executablePath": "/usr/bin/pmset",
 "shellArguments": ["sleepnow"], // optional

  • openUrl
 "action": "openUrl",
 "url": "https://google.com",

LongActions

If you want to longPress for some operations, it is similar to the configuration for Actions but with additional parameters, for example:

 "longAction": "hidKey",
 "longKeycode": 53,
  • longAction
  • longKeycode
  • longActionAppleScript
  • longExecutablePath
  • longShellArguments
  • longUrl

Additional parameters:

  • width restrict how much room a particular button will take
  "width": 34
  • align can stick the item to the side. default is center
  "align": "left" // "left", "right" or "center"
  • bordered you can do button without border
  "bordered": "false" // "true" or "false"
  • background allow to specify you button background color
  "background": "#FF0000",

by using background with color "#000000" and bordered == false you can create button without gray background but with background when the button is pressed

  • title specify button title
  "title": "hello"
  • image specify button icon
  "image": {
    //Can be either of those
    "base64": "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdB...."
    //or
    "filePath": "~/img.png"
  }

Troubleshooting

If you can't open preferences:

  • Opening another program which can't edit text
    1. Open Terminal.app
    2. Put open -a TextEdit ~/Library/Application\ Support/MTMR/items.json command and press Enter

Buttons or gestures doesn't work:

  • "After the last update my mtmr is not working anymore!"
  • "Buttons sometimes do not trigger action"
  • "ESC don't work"
  • "Gestures don't work"

Re-tick or check a tick for access 🍏→ System Preferences → Security and Privacy → tab Privacy → Accessibility → MTMR

Credits

Built by @Toxblh and @ReDetection.

Analytics

Github

link
Stars: 2192

Dependencies

Used By

Total: 0

Releases

v0.26.1 - 2020-05-17 12:56:57

Commits

  • [2e2f556]: Fixed lost margin (#313) (Fedor Zaitsev) #313
  • [3e5fa14]: v0.26.1 (Anton Palgunov)

v0.26.0 - 2020-05-14 00:08:52

v0.26

  • Custom gestures.
  • Updated few apple scripts.
  • Conditions for icon for appleScript buttons.

Thanks for all contributors, especially @FedorZaytsev

Commits

  • [0e8dab4]: Update README.md (Anton Palgunov)
  • [d6e48c8]: Update README.md (Anton Palgunov)
  • [6629cfd]: Update FUNDING.yml (Anton Palgunov)
  • [f3015df]: Update finder example script (Giovanni Tataranni) #219
  • [59cde09]: Update Finder.scpt (Giovanni Tataranni) #219
  • [66b175d]: Update README.md (Giovanni Tataranni) #219
  • [e44ff00]: support for global settings. haptic feedback as the first one (Serg) #224
  • [41a9544]: More consistent settings (Toxblh)
  • [d4b950a]: Merge branch 'ReDetection-disable-haptic' (Toxblh)
  • [0b39795]: v0.24 (Toxblh)
  • [92975cb]: resolve existing varnings (Serg) #229
  • [e68fa10]: update swift to 5.0 (Serg) #229
  • [2635e26]: switch to modern build system (Serg) #229
  • [820853d]: little cleanup (Serg) #229
  • [f2e6959]: upd travis-ci 10 to 11.2 (Toxblh) #229
  • [3f78bbe]: CI osx_image 11.2 -> 11.1 (Toxblh) #229
  • [c4928ee]: enable/disable multitouch gestures (Serg) #230
  • [cd2ec3d]: use property wrappers to have settings in a nice way. now it's the only place for settings key (Serg) #230
  • [94717a5]: missed a single userdefaults (Serg) #234
  • [f82d769]: rewrite in scrollview; get rid of custom gesture handling (Serg) #234
  • [dd23a3b]: don't reload list of apps every time (Serg) #234
  • [e9a7b6d]: get long tap to kill back into place (Serg) #234
  • [6920664]: implement regex filter for dock items (Serg) #234
  • [2cdb705]: Consolidate the two String extenstions. (Mark Rickert) #236
  • [eaa2664]: Add ability to use file paths relative to your user directory (Mark Rickert) #236
  • [855ddea]: Tests relative file paths and images. (Mark Rickert) #236
  • [5eb2d73]: Add some image filePath documentation. (Mark Rickert) #236
  • [1ae2041]: Get rid of all references to /Users/x/ in favor of ~ (Mark Rickert) #236
  • [d819988]: cleanup parser: remove other duplicates (they are defined and parsed down below in the ItemType) (Serg) #237
  • [466c0e5]: v0.25 (Toxblh)
  • [e9e5a6f]: fix yandex wheather, for correct lang (Toxblh)
  • [bdfb711]: fix pomodoro icon not showing up on catalina (Sam Flattery) #260
  • [093faa2]: Create swift.yml (Anton Palgunov)
  • [40c684f]: GitHub actions (#271) (Anton Palgunov) #271
  • [7e0db70]: Updated README (#274) (Fedor Zaytsev) #274
  • [3864591]: Update build-test.yml (Anton Palgunov)
  • [dbb2f16]: Implemented changable icons for AppleScriptTouchBarItem (#275) (Fedor Zaytsev) #275
  • [642f080]: Changeable icons for AppleScriptTouchBarItem & tests (#276) (Fedor Zaytsev) #276
  • [42ce95b]: Add Music app (#279) (Peter Hrvola) #279
  • [a0fc0b3]: Custom gestures support (#288) (Fedor Zaytsev) #288
  • [f61550e]: More Productive Gestures (#289) (Jæy) #289
  • [502f989]: Currency bar update (#293) (Simon Rogers) #293
  • [52758f9]: Fix shell crash (#297) (Fedor Zaytsev) #297
  • [6d26639]: Revert "More Productive Gestures (#289)" (Anton Palgunov)
  • [3fc75ca]: Updated workflows. For delivery unsign app in gihub (Anton Palgunov)
  • [a1f6402]: Correct file for release (Anton Palgunov)
  • [75df82a]: ignore sign error (Anton Palgunov)
  • [b6721f0]: return normal trigggers in workflows (Anton Palgunov)
  • [445584b]: Added xcpretty for test and build scripts (Anton Palgunov)
  • [bc11728]: Standard english date for build script (Anton Palgunov)
  • [1e1ae2a]: Release version 0.26 (Anton Palgunov)

Relative paths. Dock improve. Multitouch settings. Swift 5.1 - 2019-11-19 16:23:43

  • Multitouch settings & swift 5.1. (Thanks to @ReDetection)
  • Dock improvements (Thanks to @ReDetection)
    • extract to settings
    • cleanup in config parser (there were two parts reading the same, one was never executed)
    • implement filter for dock items
    • rewrite from NSScrubber to NSScrollView. mainly to fix open/terminate of the wrong app (not the one being touched), but also to fix extra dock reloads
    • more stylish frontmost app indicator
  • Relative file paths (Thanks to @markrickert)
  • Cleanup parser (Thanks to @ReDetection)

Added HapticFeedback setting - 2019-10-12 12:29:55

image

Add locale to timeButton - 2019-09-04 11:12:47

Fixes. Ya.Weather. Haptic Feedback. - 2019-07-29 11:17:13

DarkMode. Auto weight for Dock - 2019-05-22 21:56:19

Dark mode

{ "type": "darkMode" }

Dock additional property:

"autoResize": true

Network "flip" parameter. Improved stability. - 2019-03-25 12:28:46

Add an additional parameter for network widget flip for change position output and input traffic.

{
	"type": "network",
	"flip": true,
},

Network plugin - 2019-02-24 23:24:23

touch bar shot 2019-02-24 at 23 13 37

try it!

{
  "type": "network",
  "width": 80,
  "align": "right",
},

Stable AppleScript. Thanks @ReDetection - 2019-02-12 23:18:18

Fixed sometime crashes - 2019-02-06 13:49:32

Fix crashes app without timeZone - 2019-01-23 11:58:51

timeZone for timeButton - 2019-01-22 09:28:09

Attention! Works not all: en.wikipedia.org/wiki/List_of_time_zone_abbreviations

{
  "type": "timeButton",
  "formatTemplate": "dd HH:mm",
  "timeZone": "UTC"
}

Full show currency rates - 2019-01-21 17:06:48

touch bar shot 2019-01-21 at 20 02 36

Add to currency block for the full show

"full": true

The default is a short version

Fixes - 2018-10-14 18:12:08

  • Fix reversed 'hide control strip' menu checkmark behaviour
  • Fix can't re-open mtmr after closing

Fix for brightness slider - 2018-10-10 17:24:03

Fix for brightness slider. Correct API for the set new level. Used CoreDisplay.framework

Fixed privacy problems - 2018-09-26 16:27:55

Added AutoUpdater. Added License, don't need open settings for first start - 2018-09-25 23:26:34

image

NightShift, Don't disturb widgets - 2018-08-30 15:47:23

Added new widgets: touch bar shot 2018-08-30 at 16 30 23 touch bar shot 2018-08-30 at 16 30 25

  • NightShift

{
    "type": "nightShift",
},
  • Don't disturb

{
    "type": "dnd",
},

Added Keyboard illumination buttons - 2018-08-26 20:18:42

Added types

illuminationDown illuminationUp

{
    "type": "illuminationDown",
    "align": "left"
  },
  {
    "type": "illuminationUp",
    "align": "left"
  }

issue #106

Preparation for MacOS 10.14 - 2018-06-10 10:16:51

Added possible to work on MacOS 10.14

Groups, Encoding for AS, Start at Login - 2018-06-01 08:31:18

Groups

{
"type": "group",
"align": "center",
"bordered": true,
"title": "stats",
"items": [{ button }, {button}, ...]
}

Start at Login

image

PR #90

Gestures on the central part - 2018-05-22 10:34:56

Gestures on the central part:

  • two finger slide: change you Volume
  • three finger slide: change you Brightness
  • widgets grouping (subgroups)
  • possibility set custom title

Music. Few new settings. - 2018-05-14 09:47:50

New settings: image

  • Show/Hide Control Strip
  • Toggle for blacklist apps will hide MTMR if active the app in the blacklist.

New widget:

  • Music, tap for pause, longTap for next
{
  "type": "music",
  "align": "center",
  "width": 80,
  "bordered": false,
  "refreshInterval": 2,
},

few inner updates:

  • New create and setting for button
  • Better realise borderless buttons
  • Update icon in control strip
  • Changed brightness key codes for buttons

Background for buttons! And buttons with minimal width. Tap and LongTap actions - 2018-04-30 21:45:15

New config for buttons: "bordered": false - if you want to use a button with minimal width without selection a width

And now you can choose background color in HEX #RGBA "background": "#FFAA00FF"

Tap and LongTap: exp. tap:

{
...
longTapAction:
// or
tapAction: {
	"actionType": ""
	// like action
}
...
}```


small changes: 
- Battery time remaining stay like exponent for the percentage

Minor fix - 2018-04-26 13:55:57

fixed bugs - 2018-04-24 10:19:19

fixed #43 #44

You can stay comments in JSON config! - 2018-04-23 12:12:43

InputSource, sort in central, +del button, auto reload preset by changes - 2018-04-22 23:57:40

Native Widgets! - 2018-04-21 00:51:32

In the version added new 3 native widgets:

  • Weather
  • Currency
  • Battery

Updates

  • Added new action: openUrl with additional parameter url
  • Added new button: type: mute
  • FIxed reload for the central scroller
  • Updated default preset.