├── .npmrc ├── .gitattributes ├── .gitignore ├── .editorconfig ├── .github └── workflows │ └── main.yml ├── test.js ├── readme.md ├── package.json ├── license └── cli.js /.npmrc: -------------------------------------------------------------------------------- 1 | package-lock=false 2 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto eol=lf 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | yarn.lock 3 | -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.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: macos-latest 9 | strategy: 10 | fail-fast: false 11 | matrix: 12 | node-version: 13 | - 24 14 | - 20 15 | steps: 16 | - uses: actions/checkout@v5 17 | - uses: actions/setup-node@v5 18 | with: 19 | node-version: ${{ matrix.node-version }} 20 | - run: npm install 21 | - run: npm test 22 | -------------------------------------------------------------------------------- /test.js: -------------------------------------------------------------------------------- 1 | import test from 'ava'; 2 | import {execa} from 'execa'; 3 | import {fileIconToBuffer} from 'file-icon'; 4 | 5 | test('outputs location', async t => { 6 | const {stdout} = await execa('./cli.js', ['Safari'], {env: {__FILE_ICON_SHOULD_NOT_PIPE__: true}}); 7 | t.true(stdout.endsWith('icon.png')); 8 | }); 9 | 10 | test('outputs buffer when piped', async t => { 11 | const icon = await fileIconToBuffer('Safari'); 12 | const {stdout} = await execa('./cli.js', ['Safari'], {encoding: 'buffer'}); 13 | t.is(stdout.length, icon.length); 14 | }); 15 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # file-icon-cli 2 | 3 | > Get the icon of a file or app as a PNG image *(macOS)* 4 | 5 | ## Install 6 | 7 | ```sh 8 | npm install --global file-icon-cli 9 | ``` 10 | 11 | ## Usage 12 | 13 | ``` 14 | $ file-icon --help 15 | 16 | Usage 17 | $ file-icon 18 | $ file-icon > icon.png 19 | 20 | Options 21 | --size Size of the icon [Max: 1024] 22 | 23 | Examples 24 | $ file-icon Safari 25 | /tmp/86ca9400-9f34-4a64-ab24-027d80f88b46/icon.png 26 | $ file-icon com.apple.Safari 27 | /tmp/ece2b714-6c6c-4677-a57c-e0e18f7b9405/icon.png 28 | $ file-icon unicorn.jpg --size=512 29 | /tmp/c3871faa-d759-48b9-ac85-5504d712a02a/icon.png 30 | $ file-icon Safari > icon.png 31 | ``` 32 | 33 | ## Tip 34 | 35 | Get the icon as Base64: 36 | 37 | ``` 38 | file-icon --size=1024 /Applications/Safari.app | base64 39 | ``` 40 | 41 | ## Related 42 | 43 | - [file-icon](https://github.com/sindresorhus/file-icon) - API for this package 44 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "file-icon-cli", 3 | "version": "4.0.0", 4 | "description": "Get the icon of a file or app as a PNG image (macOS)", 5 | "license": "MIT", 6 | "repository": "sindresorhus/file-icon-cli", 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 | "bin": { 15 | "file-icon": "./cli.js" 16 | }, 17 | "engines": { 18 | "node": ">=20" 19 | }, 20 | "scripts": { 21 | "test": "xo && ava" 22 | }, 23 | "files": [ 24 | "cli.js" 25 | ], 26 | "keywords": [ 27 | "cli-app", 28 | "cli", 29 | "macos", 30 | "file", 31 | "icon", 32 | "app", 33 | "png", 34 | "application", 35 | "icons", 36 | "path", 37 | "filepath", 38 | "bundle", 39 | "id", 40 | "image", 41 | "size", 42 | "swift" 43 | ], 44 | "dependencies": { 45 | "file-icon": "^6.0.0", 46 | "meow": "^14.0.0", 47 | "tempy": "^3.1.0" 48 | }, 49 | "devDependencies": { 50 | "ava": "^6.4.1", 51 | "execa": "^9.6.0", 52 | "xo": "^1.2.2" 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /cli.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import process from 'node:process'; 3 | import meow from 'meow'; 4 | import {temporaryFile} from 'tempy'; 5 | import {fileIconToBuffer, fileIconToFile} from 'file-icon'; 6 | 7 | const cli = meow(` 8 | Usage 9 | $ file-icon 10 | $ file-icon > icon.png 11 | 12 | Options 13 | --size Size of the icon [Max: 1024] 14 | 15 | Examples 16 | $ file-icon Safari 17 | /tmp/86ca9400-9f34-4a64-ab24-027d80f88b46/icon.png 18 | $ file-icon com.apple.Safari 19 | /tmp/ece2b714-6c6c-4677-a57c-e0e18f7b9405/icon.png 20 | $ file-icon unicorn.jpg --size=512 21 | /tmp/c3871faa-d759-48b9-ac85-5504d712a02a/icon.png 22 | $ file-icon Safari > icon.png 23 | `, { 24 | importMeta: import.meta, 25 | }); 26 | 27 | if (process.stdout.isTTY || process.env.__FILE_ICON_SHOULD_NOT_PIPE__) { 28 | const destination = temporaryFile({name: 'icon.png'}); 29 | 30 | await fileIconToFile(cli.input[0], { 31 | size: cli.flags.size, 32 | destination, 33 | }); 34 | 35 | console.log(destination); 36 | } else { 37 | const icon = await fileIconToBuffer(cli.input[0], { 38 | size: cli.flags.size, 39 | }); 40 | 41 | process.stdout.write(icon); 42 | } 43 | --------------------------------------------------------------------------------