# electron-mac-dock-icon-switcher

> > Change your app's Dock icon on macOS, so it persists after your app quits.

Latest version **1.0.0** (published 2023-11-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install electron-mac-dock-icon-switcher
pnpm add electron-mac-dock-icon-switcher
yarn add electron-mac-dock-icon-switcher
bun add electron-mac-dock-icon-switcher
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-11-12 |
| First published | 2023-11-12 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 84.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| GitHub stars | 3 |
| Author | David Cann |
| Maintainers | davidcann |
| Keywords | electron, electronjs, dock, macos, mac |

## Links

- npm: https://www.npmjs.com/package/electron-mac-dock-icon-switcher
- Repository: https://github.com/davidcann/electron-mac-dock-icon-switcher
- Homepage: https://github.com/davidcann/electron-mac-dock-icon-switcher#readme
- Issues: https://github.com/davidcann/electron-mac-dock-icon-switcher/issues
- npm.io page: https://npm.io/package/electron-mac-dock-icon-switcher

## Recent versions

- 1.0.0 (latest) — 2023-11-12

## README

# electron-mac-dock-icon-switcher

> Change your app's Dock icon on macOS, so it persists after your app quits.

You should install this in `devDependencies` because you'll configure your build process to copy the built `.docktileplugin` bundle into a folder inside your app bundle. Because of this, the switching icons can only work with your production app, not when running with the electron binary used in development.

## Xcode Requirements

You must have `xcodebuild` installed and working properly. It comes with Xcode, but if there's an error, you may need to run `sudo xcode-select --reset` or use the `-switch` argument to set the location of your Xcode tools.

## Install

    npm install --save-dev electron-mac-dock-icon-switcher

### Set Variable in `.npmrc`

You must add the three variables in your app's `.npmrc` file. Each string **must be unique** to your app.

- `dock_icon_notification_key` is used as the system-wide macOS notification key for the "set" icon action. It is typically a reverse dns style string.
- `dock_icon_plugin_bundle_identifier` is used as the unique identifier of the plugin bundle. It is typically a reverse dns style string. Note that this should be different from your app's bundle identifier.
- `dock_icon_class_name` is used as the class name of the plugin that is loaded by the dock. It is typically a camel case first-letter-capitalized string, with a prefix unique to the developer or your project.

An example `.npmrc` file:

    dock_icon_notification_key=com.demo.docktile.set
    dock_icon_plugin_bundle_identifier=com.demo.docktile.plugin
    dock_icon_class_name=MyDemoDockTilePlugin

If you change any of these values after running once, you'll need to clear the dock's cache between runs. Quit the app, remove it app from the dock, wait 5 seconds, then restart the `Dock` and `SystemUIServer` services:

    sudo killall Dock
    sudo killall SystemUIServer

### Build Phase Requirements

1. Set `NSDockTilePlugIn` in your app's Info.plist
2. Copy `DockTile.docktileplugin` bundle to your app's bundle

`forge.config.cjs` example:

    module.exports = {
    	extendInfo: {
    		NSDockTilePlugIn: "DockTile.docktileplugin",
    	},
    	packagerConfig: {
    		afterComplete: [
    			(buildPath, electronVersion, platform, arch, callback) => {
    				if (platform == "darwin") {
    					// Copy the plugin to the app bundle
    					const fs = require("fs");
    					const path = require("path");
    					const pluginPath = path.join(
    						__dirname,
    						"node_modules",
    						"electron-mac-dock-icon-switcher",
    						"build",
    						"Release",
    						"DockTile.docktileplugin"
    					);
    					const pluginDest = path.join(
    						buildPath,
    						"MyApp.app", // TODO: replace with your bundle name
    						"Contents",
    						"PlugIns",
    						"DockTile.docktileplugin"
    					);
    					fs.mkdirSync(pluginDest, { recursive: true });
    					fs.cpSync(pluginPath, pluginDest, { recursive: true, overwrite: true });
    				}
    				callback();
    			},
    		],
    	}
    	...
    }

## Signing

You may need to sign the DockTile.docktileplugin bundle before distributing your app.

**TODO**: add instructions for signing with `electron-forge`

## Not Allowed in Mac App Store

Last I heard, Apple does not allow apps with a docktileplugin in the Mac App Store.

## Debugging

Build manually after checking out this repository:

    ./build.sh

Fixes some xcodebuild cli errors:

    sudo xcode-select --reset

Check the plugin's binary to make sure your notification key is set correctly:

    strings ./build/Release/DockTile.docktileplugin/Contents/MacOS/DockTile

---
_Source: https://npm.io/package/electron-mac-dock-icon-switcher · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
