brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: open -a opens a file in the app you pick, not the default one

Terminal
~/tips/tip-macos-open-a-application

open -a Preview *.png

Opens files in a specific app from the terminal, without changing your default app.

Plain open file does what a double-click does, so a PNG lands in whatever app macOS thinks owns PNGs. Half the time I want something else, and the -a flag lets me name the app right on the command line.

Give -a the name of the app, then the files. The name is the one you see in the Applications folder, without .app, and quotes are needed when it has spaces:

open -a Preview *.png
open -a "Visual Studio Code" .

The first line throws every PNG in the folder into Preview in one go, the second opens the current folder as a project. If you’d rather not depend on the display name, -b takes the bundle identifier instead, so open -b com.apple.TextEdit notes.txt always hits TextEdit.

Two more flags combine nicely with -a. -g opens the file without pulling the app to the front, handy in a script. -n starts a new instance even when the app is already running, and anything after --args is passed to the app itself instead of being treated as files to open.

The caveat is that -a only changes this one launch. Your default app for that file type stays the same, so double-clicking still uses the old one. For a permanent change, use Get Info in Finder and the Open with section there. And if you mistype the app name, open just says it can’t find it, so check the spelling against /Applications.

Further reading: open man page (SS64)

More Terminal tips ioreg -rn AppleSmartBattery | grep CycleCount Terminal can save your windows and tabs as a window group Export a Terminal profile to a .terminal file and import it on another Mac mc hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000039,"HIDKeyboardModifierMappingDst":0x700000029}]}' All Terminal tips (116) All topics

Link