All Projects → Worie → btt

Worie / btt

Licence: MIT license
Low level MacOS management in JavaScript via BetterTouchTool

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to btt

btt-touchbar-preset
🧰 My TouchBar BTT preset
Stars: ✭ 18 (-80.43%)
Mutual labels:  touchbar, bettertouchtool
awesome-btt-config
An curated list of awesome BetterTouchTool configs.
Stars: ✭ 38 (-58.7%)
Mutual labels:  touchbar, bettertouchtool
Lowlevelprogramming University
How to be low-level programmer
Stars: ✭ 7,224 (+7752.17%)
Mutual labels:  low-level, system-programming
Aquatouch
Dynamic Custom Macros for your MacBook TouchBar! (Supports 40+ Apps and Websites)
Stars: ✭ 125 (+35.87%)
Mutual labels:  touchbar, keyboard-shortcuts
Intel-Realsense-Hand-Toolkit-Unity
Intel Realsense Toolkit for Hand tracking and Gestural Recognition on Unity3D
Stars: ✭ 72 (-21.74%)
Mutual labels:  gesture, gesture-recognition
mapbox-gestures-android
The Mapbox Gestures for Android library makes it easy to detect and handle user gestures on an Android device.
Stars: ✭ 25 (-72.83%)
Mutual labels:  gesture, gesture-recognition
gesto
You can set up drag, pinch events in any browser.
Stars: ✭ 47 (-48.91%)
Mutual labels:  gesture, gesture-recognition
GIMLeT
GIMLeT – Gestural Interaction Machine Learning Toolkit
Stars: ✭ 33 (-64.13%)
Mutual labels:  gesture, gesture-recognition
Webview-unity-3d-2017.3-or-higher-
Webview unity 3d 2017.3 or higher - can be open website url on unity3d or open Html5, html and js on unity offline
Stars: ✭ 18 (-80.43%)
Mutual labels:  webview
EasyBrowser
尝试实现一个简易的Android浏览器。支持标签页的创建,切换,缓存。
Stars: ✭ 34 (-63.04%)
Mutual labels:  webview
TensorFlow-Multiclass-Image-Classification-using-CNN-s
Balanced Multiclass Image Classification with TensorFlow on Python.
Stars: ✭ 57 (-38.04%)
Mutual labels:  low-level
touchbar
Atom package to use MacBook Touchbar
Stars: ✭ 51 (-44.57%)
Mutual labels:  touchbar
AFWebViewController
In-app browser that uses WKWebView
Stars: ✭ 38 (-58.7%)
Mutual labels:  webview
hera-workflows
Hera is an Argo Workflows Python SDK. Hera aims to make workflow construction and submission easy and accessible to everyone! Hera abstracts away workflow setup details while still maintaining a consistent vocabulary with Argo Workflows.
Stars: ✭ 252 (+173.91%)
Mutual labels:  workflow-automation
btt-quicknav
HTML overlay for quickly navigating your computer
Stars: ✭ 20 (-78.26%)
Mutual labels:  bettertouchtool
gest
Hand gestures as an input device
Stars: ✭ 37 (-59.78%)
Mutual labels:  gesture-recognition
react-keybind
A lightweight library to manage global keyboard shortcuts for your React application
Stars: ✭ 35 (-61.96%)
Mutual labels:  keyboard-shortcuts
TrendingCustomAlert
You can use a ready-made custom alert controller.
Stars: ✭ 25 (-72.83%)
Mutual labels:  webview
pam-touchid
Pluggable Authentication Module for TouchID enabled MacBooks
Stars: ✭ 32 (-65.22%)
Mutual labels:  touchbar
writebar
Experimental distraction-free text editor, based on the Macbook pro TouchBar
Stars: ✭ 37 (-59.78%)
Mutual labels:  touchbar

btt

Package logo

Package version Vunerabilities

Vunerabilitiesn

Manage your BetterTouchTool in JavaScript, easily.

Get started

See the guide and api for btt.js.

About

This package is a handy wrapper over BetterTouchTool built in webserver API. (by @Andreas Hegenberg)

This package will allow you to automate you MacOS-running machine using JavaScript. You'll be able to:

  • Create event listeners that'll run within an operating system, outside the browser!
  • Toggle your do-not-disturb state
  • Show a system notification
  • Toggle Night Shift
  • Sleep your computer after timeout
  • Create your own touchbar widgets
  • Feel a notification via haptic engine
  • Control the brightness of the screen and keyboard
  • Control the volume levels
  • Use the content of your clipboard to be opened in a specific url or application
  • Create your own UIs "within system" using web view
  • Trigger a system-wide keyboard shortcut
  • Send a shortcut to a specific application
  • Show / Hide / Open / Quit a specific applcation
  • Move your mouse to a specific position and click
  • Hide your cursor
  • Lock / Unlock your MacOS machine
  • Integrate your flow / touchbar with various APIs ...

and anything else that BetterTouchTool or the JavaScript specification will allow you to do!

Typed, browser/server side library

This package provides its own type definitions and can be run both on browser (using module bundlers) and in a nodejs environment.

Requirements

This package depends on the application BetterTouchTool in at least version v2.0.0, you need to have it installed and running before going further.

Then, please enable and configure the webserver in the BetterTouchTool preferences. You're now ready to go!

Installation

npm install btt

Example usage

First, create a btt instance passing the required data for BTT webserver.

// import Btt class from the package
import { Btt } from 'btt';

// create an instance representing btt webserver
// can be remote or local
const btt = new Btt({
  domain: '127.0.0.1',
  port: 8000,
  protocol: 'http',
  version: '2.525',
});

Now you can invoke the actions - there are plenty of ways to do it, and all are promise-based.

// sequentially run three actions - spotlight, type text and night shift
// as all actions are promise-based, you can use async/await notation without hassle
btt
  .triggerShortcut('cmd+space').invoke()
  .then(() => btt.sendText({ text: 'Hello world!'}).invoke())
  .then(() => btt.toggleNightShift().invoke());

Response structure for every action

// every single action returns a CallResult object containing information about the Call

interface CallResult {
  time: number;     // contains time in MS that this action took to perform (including fetch time)
  status: number;   // contains an HTTP status / string
  value: any;       // depending on the method used, may return an array, object or fetch result
  note?: string;    // an additional note for the user
}

Chaining methods

// you can also use a custom chain method to simplify even more and avoid using async/await
btt
  .invokeChain()                      // 1)
  .triggerShortcut('cmd+space')       // 2)
  .sendText({text: 'Hello world!'})   // 3)
  .wait(1000)                         // 4)
  .toggleNightShift()                 // 5)
  .call()                             // 6)
  .then(v => console.info(v))         // 7)

// Explanation:
// 1) Starts method chaining
// 2) Action that a user wants to perform
// 3) Action that a user wants to perform
// 4) Additional method available in chain only - wait before triggering next action
// 5) Action that a user wants to perform
// 6) Invokes all previously-defined actions, ensuring the execution order
// 7) Returns a promise that resolves once all of the actions are fulfilled. 
//    Contains information about the status of the chain (time, value, status)

Event listeners

You can even register a system-wide event listener within BTT that'll trigger particular actions

// creates a trigger in BetterTouchTool. Keep in mind that this is persistent until you manually delete it!
btt.addTriggerAction('oneFingerForceClick', (ev) => {

  // create a list of actions that you want to perform on single finger force click
  const actionsToInvoke = [
    btt.showHUD({
      title: 'Wow!',
      details: 'I triggered! 😍',
    }),
  ];
  
  // and push them to `actions` property in the event object.
  ev.actions.push(...actionsToInvoke);
});

// you can also delete an event listener - trigger: 
btt.removeTriggerAction('oneFingerForceClick', callbackFuntion);

The above method will trigger the callback upon running your script, not when a particular event really occurs. If you need to call a function upon event recognition, you need to use btt-node-server and use the addEventListener and removeEventListener methods on the btt instance. The callback you provide will run in the nodejs environment, within vm.

const btt = new Btt({
  domain: '127.0.0.1',
  port: 8000,
  protocol: 'http',
  version: '2.525',
  // pass eventServer to use this part of the lib
  eventServer: {
    domain: 'localhost',
    port: 8888,
  },
});

// adds real event listener, that'll run once event occurs
btt.addEventListener('cmd+ctrl+alt+u', async (ev) => {
  // write the code as you'd normally do -> trigger the action for some interval
  const intervalID = setInterval(() => {
    btt.showHUD({ title: 'It works!'}).invoke();
  }, 1000);

  // you can use fetch API here or anything that your node version will support

  // stops the interval after 10 seconds
  await new Promise((res, rej) => {
    setTimeout(() => {
      clearTimeout(intervalID);
      res();
    }, 10000);
  });
  
  // the value you return from the callback will be the response of the btt-node-server 
  return { messsage: 'Hello world!' };
});

To get all available events, you have to look in the enums (list of all valid events will be available soon). Most of the time you can just guess because all event names are the lowercased equivalent of the triggers from within BetterTouchTool.

Additional action information

For use within the browser, you can get the url that lies behind all actions and assign it to some <a href="${link}">Link</a>. To get link you simply need to read the .url property of any action:

console.log(
  btt.triggerShortcut('cmd+space').url
);

If you want to have a peak at the generated action JSON, or want to share it with others who use BetterTouchTool you can read the .json property of any action.

console.log(
  btt.showHUD({ title: 'Hello!' }).json
);

More examples

For more advanced examples visit the example section

Notice

Keep in mind that this module only provides handy utility functions that send requests to BTT built in webserver. So depending on your BTT version, some actions may be glitchy. Do not hestitate to report those issues here or in the official BTT community forum.

Also, keep in mind that accessing any kind of low level APIs from JS may be dangerous, make sure to stay secure

Related projects:

  • btt - BetterTouchTool management in JS
  • btt-node-server - Simple express server, required for advanced event listener handling
  • btt-node Premature version of this package (btt) - deprecated

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].