Live data from Hacker News

macOS command-line tools you might not know about

saurabhs.org

181–190 of 454 posts

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

#181
post #45

Nice list. Also, hidutil ( https://developer.apple.com/library/archive/technotes/tn2450... ). Example: hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000049,"HIDKeyboardModifierMappingDst":0x700000065}]}' For my PC keyboard, remaps "Ins" (normally useless under macOS) to something ("PC Execute") I can trap and remap with Keyboard Maestro.

hidutil property --set '{"UserKeyMapping":[{"HIDKeyboardModifierMappingSrc":0x700000064,"HIDKeyboardModifierMappingDst":0x700000035}]}' Remaps top left key on Euro-style keyboards from useless "paragraph" to useful "backtick".

Yes, this is great... I was given a Macbook with a Norweigan keyboard for testing a port of FreeBSD on it, and I quickly discovered that the keyboard layout remapping stuff available via the UI won't remap at least this one key to what I'd find on my US keyboard.

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

#182
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...

It would have avoided it! I was using tab and forgot to select .pub as you correctly surmised. I was a junior dev at the time and all the seniors got a good laugh out of it, and I use it as a cautionary tale about trying to be TOO overeager and efficient.

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

#183

Earlier quoted context omitted.

That's a useless use of cat. You can use `jq . foo.json | pbcopy` or `jq < foo.json | pbcopy`.

Speaking for myself, the first form is more natural- even if it’s a useless cat, because I’m always cat-ing files to see their structure. Then progressively tacking on different transforms. And then finally putting it in whatever I want as output. It’s so ingrained, I’m more likely than not to just write it out that way even when I know exactly what I’m doing from the onset.

I've been using bat as a cat replacement for a while now. It includes paging, syntax highlighting, line numbers, and is generally very performant.

https://github.com/sharkdp/bat

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

#184
post #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))

Or directly from the commandline:

    pbcopy | python -c 'import sys; import json; print(json.load(sys.stdin))' | pbpaste

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

#187
Shoutout to the `diskutil` command line utility on macOS.

I had problems with some slices on a disk today, and was not able to fix it with the graphical Disk Utility that comes with macOS. These slices were remnants from experimenting with running Asahi Linux on the machine in the past.

I knew there had to be a way to fix it with diskutility cli program.

I found a thread, and the solution for what to do in such situation.

https://apple.stackexchange.com/questions/411544/cant-reclai...

Now the disk can be fully utilised by macOS again.

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

#188
Needs to mention afplay for playing audio! You can easily use this to make a command-line MP3 player.

Others have mentioned the “say” utility for speech synthesis. There is a lot you can do with it, it supports the TUNE format, which allows you to "shape the overall melody and timing of an utterance... for example ... to make an utterance sound as if it is spoken with emotion".

See: Apple's Speech Synthesis Programming Guide, https://josh8.com/blog/img/speech-synthesis.pdf

I also wrote more about this here: https://josh8.com/blog/commandline-audio-mac.html

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

#189

Earlier quoted context omitted.

Speaking for myself, the first form is more natural- even if it’s a useless cat, because I’m always cat-ing files to see their structure. Then progressively tacking on different transforms. And then finally putting it in whatever I want as output. It’s so ingrained, I’m more likely than not to just write it out that way even when I know exactly what I’m doing from the onset.

Yes, this iterative procedure is often why "useless" cats get put into it. It's a very effective way of processing regular text information. e.g. I need to grab some info from textfile.txt to use as arguments to a function. cat textfile.txt looks like its comma delimited. cat textfile.txt | cut -d, -f 2-5 ah, its the third and fourth column i need cat textfile.txt | cut -d, -f 3-4 | grep '123456' perfect cat textfile…

> cat textfile.txt

> looks like its comma delimited.

Interesting; why wouldn't you use `head`? Who knows how big textfile.txt is?

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

#190
post #172
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.

It's cool to use pbcopy and pbpaste with your phone! Copy some text on the phone, and you can pbpaste it onto the Mac command line. So cool.

It creeps me out when the clipboard is unexpectedly shared between my phone and computer. And since the feature seems to turn on randomly but not reliably when I want it to, I’d rather it just didn’t exist.
Post reply on HN