├── .gitignore ├── package.json ├── readme.md └── index.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "macos-startup", 3 | "version": "0.0.1", 4 | "description": "Get list of macOS startup items.", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "bin": { 10 | "startup_items": "./index.js" 11 | }, 12 | "keywords": [ 13 | "macos", 14 | "startup" 15 | ], 16 | "author": "", 17 | "license": "MIT", 18 | "dependencies": { 19 | "plist": "^3.0.4" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # macos-startup 2 | 3 | Get list of macOS startup items. 4 | 5 | Under macos, some software will automatically start after installation. The purpose of this software is to obtain the list of macos startup items. 6 | 7 | If you want to disable auto-start, just rename the corresponding plist file to a non-plist suffix and restart your mac. 8 | 9 | If you want to see which app a plist file corresponds to, you can use the cat command to see. 10 | 11 | Some plist files may not be parsed correctly. 12 | 13 | plist files that start with com.apple will be ignored. 14 | 15 | ## Prerequisites 16 | 17 | [Node.js](https://nodejs.org/) 18 | 19 | ## Installation 20 | 21 | ```shell 22 | npm i -g macos-startup 23 | ``` 24 | 25 | ## Usage 26 | 27 | ```shell 28 | startup_items 29 | ``` 30 | 31 | ## License 32 | 33 | Distributed under the MIT License. 34 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | const os = require("os"); 4 | const plist = require("plist"); 5 | const fs = require("fs"); 6 | const cp = require("child_process"); 7 | 8 | const dirs = [ 9 | "/Library/LaunchDaemons", // Runs when the system starts and also runs when the user is not logged in 10 | "/Library/LaunchAgents", // Run after user log in 11 | `${os.homedir()}/Library/LaunchAgents`, // User-defined user startup items 12 | "/System/Library/LaunchDaemons", // The system's own startup items 13 | "/System/Library/LaunchAgents", // The system's own startup items 14 | ]; 15 | 16 | // keep plist library from printing parse error 17 | const warn = console.warn; 18 | const error = console.error; 19 | 20 | console.warn = console.error = function () {}; 21 | 22 | const autoStartList = []; 23 | const parseErrorList = []; 24 | dirs.forEach((dir) => { 25 | const existed = fs.existsSync(dir); 26 | if (!existed) { 27 | return; 28 | } 29 | 30 | fs.readdirSync(dir).forEach((file) => { 31 | if (file.endsWith(".plist")) { 32 | const filePath = `${dir}/${file}`; 33 | if (file.startsWith("com.apple")) { 34 | return; 35 | } 36 | if (!file.endsWith(".plist")) { 37 | return; 38 | } 39 | const content = fs.readFileSync(filePath, "utf8"); 40 | try { 41 | const obj = plist.parse(content); 42 | if (obj.KeepAlive || obj.RunAtLoad) { 43 | autoStartList.push(filePath); 44 | } 45 | } catch (e) { 46 | parseErrorList.push(filePath); 47 | } 48 | } 49 | }); 50 | }); 51 | 52 | console.log("AutoStart:"); 53 | autoStartList.forEach((file) => { 54 | console.log(" ", file); 55 | }); 56 | console.log(""); 57 | console.log("ParseError:"); 58 | parseErrorList.forEach((file) => { 59 | console.log(" ", file); 60 | }); 61 | --------------------------------------------------------------------------------