├── .editorconfig ├── .gitattributes ├── .github └── workflows │ └── main.yml ├── .gitignore ├── .npmrc ├── index.d.ts ├── index.js ├── index.test-d.ts ├── license ├── package.json ├── readme.md └── test.js /.editorconfig: -------------------------------------------------------------------------------- 1 | root = true 2 | 3 | [*] 4 | indent_style = tab 5 | end_of_line = lf 6 | charset = utf-8 7 | trim_trailing_whitespace = true 8 | insert_final_newline = true 9 | 10 | [*.yml] 11 | indent_style = space 12 | indent_size = 2 13 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.github/workflows/main.yml: -------------------------------------------------------------------------------- 1 | name: CI 2 | on: 3 | - push 4 | - pull_request 5 | jobs: 6 | test: 7 | name: Node.js ${{ matrix.node-version }} 8 | runs-on: ubuntu-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 16 14 | - 14 15 | - 12 16 | steps: 17 | - uses: actions/checkout@v2 18 | - uses: actions/setup-node@v2 19 | with: 20 | node-version: ${{ matrix.node-version }} 21 | - run: npm install 22 | - run: npm test 23 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /index.d.ts: -------------------------------------------------------------------------------- 1 | export type AnybarStatus = 2 | | 'white' 3 | | 'red' 4 | | 'orange' 5 | | 'yellow' 6 | | 'green' 7 | | 'cyan' 8 | | 'blue' 9 | | 'purple' 10 | | 'black' 11 | | 'question' 12 | | 'exclamation' 13 | | 'quit' 14 | | 'filled' 15 | | 'hollow'; 16 | 17 | export interface Options { 18 | /** 19 | The port to communicate with the AnyBar app. 20 | 21 | @default 1738 22 | */ 23 | readonly port?: number; 24 | } 25 | 26 | /** 27 | Control the [AnyBar app](https://github.com/tonsky/AnyBar). 28 | 29 | @param status - The [name](https://github.com/tonsky/AnyBar#usage) of the color dot you want the AnyBar app to display. 30 | @returns Returns a promise, but the AnyBar app doesn't send back a reply, so really the only point of waiting for the promise to resolve is in case of an obscure DNS error. 31 | 32 | @example 33 | ``` 34 | import anybar from 'anybar'; 35 | 36 | anybar('purple'); 37 | // The Anybar app menu bar icon turned purple 38 | ``` 39 | */ 40 | export default function anybar(status: AnybarStatus, options?: Options): Promise; 41 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | import {promisify} from 'util'; 2 | import dgram from 'dgram'; 3 | 4 | export default async function anybar(status, {port = 1738} = {}) { 5 | if (typeof status !== 'string') { 6 | return Promise.reject(new TypeError(`Expected \`status\` to be string, got ${typeof status}`)); 7 | } 8 | 9 | const message = Buffer.from(status); 10 | const client = dgram.createSocket('udp4'); 11 | 12 | await promisify(client.send.bind(client))(message, 0, message.length, port, 'localhost'); 13 | client.close(); 14 | } 15 | -------------------------------------------------------------------------------- /index.test-d.ts: -------------------------------------------------------------------------------- 1 | import {expectType, expectError} from 'tsd'; 2 | import anybar from './index.js'; 3 | 4 | expectType>(anybar('red')); 5 | expectType>(anybar('red', {port: 123})); 6 | expectError(anybar('foo')); 7 | -------------------------------------------------------------------------------- /license: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Sindre Sorhus (https://sindresorhus.com) 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "anybar", 3 | "version": "5.1.0", 4 | "description": "Control the AnyBar app", 5 | "license": "MIT", 6 | "repository": "sindresorhus/anybar", 7 | "funding": "https://github.com/sponsors/sindresorhus", 8 | "author": { 9 | "name": "Sindre Sorhus", 10 | "email": "sindresorhus@gmail.com", 11 | "url": "https://sindresorhus.com" 12 | }, 13 | "type": "module", 14 | "exports": "./index.js", 15 | "engines": { 16 | "node": ">=12" 17 | }, 18 | "scripts": { 19 | "test": "xo && ava && tsd" 20 | }, 21 | "files": [ 22 | "index.js", 23 | "index.d.ts" 24 | ], 25 | "keywords": [ 26 | "anybar", 27 | "app", 28 | "macos", 29 | "mac", 30 | "udp", 31 | "status", 32 | "color", 33 | "dot", 34 | "indicator" 35 | ], 36 | "devDependencies": { 37 | "ava": "^3.15.0", 38 | "tsd": "^0.14.0", 39 | "xo": "^0.39.1" 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # anybar 2 | 3 | > Control the [AnyBar app](https://github.com/tonsky/AnyBar) 4 | 5 | [![](https://cloud.githubusercontent.com/assets/170270/24325650/cdde4f9e-11cf-11e7-8e1d-5dee07e3c77d.png)](https://github.com/tonsky/AnyBar) 6 | 7 | ## Install 8 | 9 | ``` 10 | $ npm install anybar 11 | ``` 12 | 13 | ## Usage 14 | 15 | ```js 16 | import anybar from 'anybar'; 17 | 18 | anybar('purple'); 19 | // The Anybar app menu bar icon turned purple 20 | ``` 21 | 22 | ## API 23 | 24 | ### anybar(status, options?) 25 | 26 | Returns a promise, but the AnyBar app doesn't send back a reply, so really the only point of waiting for the promise to resolve is in case of an obscure DNS error. 27 | 28 | #### status 29 | 30 | Type: `string` 31 | 32 | The [name](https://github.com/tonsky/AnyBar#usage) of the color dot you want the AnyBar app to display. 33 | 34 | #### options 35 | 36 | Type: `Object` 37 | 38 | ##### port 39 | 40 | Type: `number`\ 41 | Default: `1738` 42 | 43 | The port to communicate with the AnyBar app. 44 | 45 | ## Related 46 | 47 | - [anybar-cli](https://github.com/sindresorhus/anybar-cli) - CLI for this module 48 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import anybar from './index.js'; 3 | 4 | test('send', async t => { 5 | await t.notThrowsAsync(anybar('green')); 6 | }); 7 | 8 | test('custom port', async t => { 9 | await t.notThrowsAsync(anybar('red', {port: 1000})); 10 | }); 11 | --------------------------------------------------------------------------------