News for hackers. Stuff that matters.
Re:Tell HN: macOS's `open` util is nifty by codetrotter on Friday June 23, 2023 @08:30AM (#36445948)
Yep, `open` is great

I regularly use it to open a Finder window with the current directory

On Linux there is a similar tool called `xdg-open` for graphical desktop environment users

Re:Tell HN: macOS's `open` util is nifty by recov on Friday June 23, 2023 @10:47AM (#36447535)
My favorite simple alias is just "alias run=xdg-open $1"
Re:Tell HN: macOS's `open` util is nifty by DamonHD on Friday June 23, 2023 @08:47AM (#36446097)
Neat, thanks, did not know about this!
Re:Tell HN: macOS's `open` util is nifty by latexr on Friday June 23, 2023 @09:03AM (#36446264)
-a is a good example for opening with the non-default app (tip: leave out the file argument to simply launch the app), but to open specifically with TextEdit there is -e:

    open -e example.csv
And -t opens with the default text editor.

Other useful options include -j to launch the app hidden, -R to reveal the file in the Finder, -W to stop execution until the app exits (useful for scripts), and -n to launch a new instance of the app (new icon will show up in the Dock). You can connect multiple flags for more complex effects.

For example, I have a script which opens iA Writer and waits until I close it before continuing. If I already have it open and editing other stuff, -W will wait for that instance of the app to close, which is a bother. So instead I do:

    open -Wna 'iA Writer' example.txt
Which opens a new instance of the app and waits until that one is closed, thus avoiding interfering with previous work.

Highly recommend taking a look at man open. It isn’t long but it is quite useful.

Re:Tell HN: macOS's `open` util is nifty by sircastor on Friday June 23, 2023 @10:59PM (#36455039)
I’ll throw in here that you can very easily copy a file path in finder by right clicking on the file, and holding down the option key and selecting the menu item that says so.

Alternatively, you can drag a file into the terminal and it will paste the file path there, which is really cool.

Re:Tell HN: macOS's `open` util is nifty by psyklic on Saturday June 24, 2023 @03:23AM (#36456407)
Similarly on Windows:

- Open current directory in Explorer:

  explorer .
- Open a file (prompts which program to open it with):

  explorer README.md
Re:Tell HN: macOS's `open` util is nifty by pomalat on Saturday June 24, 2023 @08:25AM (#36458095)
It's poor man's plumb(1) from Plan 9: https://9p.io/wiki/plan9/using_plumbing/index.html