Live data from Hacker News

macOS command-line tools you might not know about

saurabhs.org

151–160 of 454 posts

Re: macOS command-line tools you might not know about

#151
post #102
post #90

Surprised pngpaste isn't mentioned (in the article nor the comments). If you take a screen shot (command + shift + 4) or partial screen shot (command + shift + control + 4) you can save it directly to an image file with: pngpaste filename.png

command shift 4 already saves a file, maybe you were thinking about command + shift + control + 3?

IIRC Cmd+shift+4 by default stores to a file, but it is easily changeable in settings. Mine has been set to store to clipboard since a long time ago (since i mostly ever take them to send to someone in chat or to insert into my own notes, for which clipboard is exactly what i need).

To change it: open Screenshot app (either cmd+shift+5 or from the app launcher), click Options in the center bar, and set "Save to" to "clipboard". Now, all screenshots in the future will be going by default to clipboard. You can also pick many other destinations for saving, including any arbitrary directory or many other apps (e.g., mail, preview, etc.).

After some googling TIL, apparently if you use Ctrl key modifier with any screenshot shortcuts (cmd+shift+3/4), it will store to clipboard regardless of your setting. Kinda nifty for those who switch between storing to file/clipboard all the time.

Re: macOS command-line tools you might not know about

#152

Another good one is 'hidutil' which can remap any keys without additional software. It's handy for things like remapping CapsLock to anything, etc. For actual full keyboard layouts though I'd use Ukelele[0]. [0] https://software.sil.org/ukelele

There is a helper tool for hidutil https://hidutil-generator.netlify.app/

> It's handy for things like remapping CapsLock to anything

It's a built-in MacOS feature that you can find in the keyboard settings.

Re: macOS command-line tools you might not know about

#153
post #22

When mentioning `open` they should have noted that `open ` will open the given file with its associated app. It’s indispensable.

More than that, it sends a message to launchd/the app instead of forking on the spot.

Sadly the app does get the shell's environment and it can't be disabled:

     Opened applications inherit environment variables just as if you had
     launched the application directly through its full path.  This behavior
     was also present in Tiger.
Why this matters, e.g with vscode:

    - ensure vscode is fully closed
    - enter project directory, something sets vars in your shell (you manually or automatically via direnv)
    - code .
    - vscode process now has the env from the shell it was started
    - open another directory from the UI
    - vscode forks and inherits from its parent process, thus the other project window has the original shell's env
    - go to another directory
    - code .
    - vscode finds out it's already running, forks and opens another window. this window has the original shell env
    - fully quit vscode and reopen it, but via the app in /Applications
    - vscode opens, now has a blank environment for its main process, and forks form there to restore previous windows, which now lack the environment they had
It's a) completely inconsistent and b) dangerous: imagine the original shell had a setting or secret in an env var that was shared to the second project (e.g virtualenv, deploy target, deployment key...)

The same issue can happen with other apps but also tmux (the tmux daemon is spawned from the first tmux command, and then subsequent sessions from tmux-server; doing it another way is possible but nontrivial)

https://github.com/microsoft/vscode/issues/15452

https://github.com/microsoft/vscode/issues/108804#issuecomme...

Re: macOS command-line tools you might not know about

#154
For audio there're also `afinfo` to probe metadata and `afconvert` to convert between different codec/container formats. I use them for podcast post-processing and archiving workflow.

macOS 13 Ventura ships with a customized `iperf3` called `iperf3-darwin` adding features like QUIC/L4S/MPTCP.

Re: macOS command-line tools you might not know about

#155
post #8

`pbcopy` and `pbpaste` are one of my most-loved in the list. Dealing with some minified json, switching to iTerm, doing `pbpaste | json_pp | pbcopy` and having a clean output is _so_ nice.

Oh man. I recently threw together a "j2p" script to make converting between json and python dicts simpler, and combining it with pbcopy/pbpaste will make it so much better:

  #!/usr/bin/env python3
  import sys
  import json
  
  print(json.load(sys.stdin))

Re: macOS command-line tools you might not know about

#156

For audio there're also `afinfo` to probe metadata and `afconvert` to convert between different codec/container formats. I use them for podcast post-processing and archiving workflow. macOS 13 Ventura ships with a customized `iperf3` called `iperf3-darwin` adding features like QUIC/L4S/MPTCP.

QUIC already? Cool

Re: macOS command-line tools you might not know about

#157

While you're at it, `brew install coreutils`. The coreutils that ship with macOS lack a lot of features available on Linux. If you use bash, I recommend upgrading it, too, since Apple ships a 16 year old build (iirc due to legal issues associated with GPLv3) `brew install bash`

They're shipping zsh now.

That's why I said "if you use bash"

Re: macOS command-line tools you might not know about

#159
post #138

While you're at it, `brew install coreutils`. The coreutils that ship with macOS lack a lot of features available on Linux. If you use bash, I recommend upgrading it, too, since Apple ships a 16 year old build (iirc due to legal issues associated with GPLv3) `brew install bash`

They come from BSD (and, nitpick, are not called coreutils). These BSD tools lack features mostly only if you're used to GNU coreutils. The expanse of GNU coreutils features is questionable too: some are nice, some you can do without easily and rarely to never miss, and some are downright annoying (yes I'm looking at you, ls with colors+quotes)

Obviously everything is preference, but I prefer things like expanded regex in gnu grep to the underpowered macOS utils

Re: macOS command-line tools you might not know about

#160
post #120

Earlier quoted context omitted.

I love this tool too! except one time I quickly typed `cat ~/.ssh/mykey | pbcopy` And sent it straight away to my coworker on Slack. I then spent the rest of the day making a new private key and adding my new pubkey to all of the 1000+ servers I had root access to. I mean we had tools to help but it still wasn’t fun. With great power/convenience comes the potential to do dumb things at lightning speeds!

I might start naming my private key files ~/.ssh/keyname.PRIVATE after hearing that story...

That's not a bad idea. I've never actually made the same mistake, but I have caught it at the last moment and having tab complete not pick the private one first would help.
Post reply on HN