Live data from Hacker News

macOS command-line tools you might not know about

saurabhs.org

311–320 of 454 posts

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

#311

`caffeinate` is a game changer. Now I can keep my Slack status green without sitting in an empty zoom room. #WFHLife ;)

Amphetamine does the same thing, but with a task bar icon and better usability: https://apps.apple.com/us/app/amphetamine/id937984704?mt=12

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

#312
post #308

Earlier quoted context omitted.

You may have to install extra voices somehow, looking at the manpage for say, it seems like 'say -v ?' would list the voices installed, but I don't seem to have any (like Whisper), though plain old 'say "hello world"' does do a robotic voice which must be the default.

You can install additional voices in System Settings → Accessibility → Spoken Content → System voice → Manage voices (in Ventura). "Whisper" is listed under "English (US) - Novelty".

Thanks, I found those with some digging, I see that even just adding Whisper it's a 3.8GB dl, mostly to upgrade the default voice apparently - I guess that's why it isn't all included by default I guess!

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

#313
post #98

Earlier quoted context omitted.

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

In what way do you see those alternatives as superior?

It usually doesn't matter much, but there are some situations where it can matter a lot. For one thing, you can't use seek() on a pipe, so e.g. `cat bigfile | tail` has to read through the entire file to find the end, but `tail bigfile` will read the file backward from the end, completely skipping the irrelevant beginning and middle. With `pv bigfile | whatever`, pv (which is basically a pipeline progress indicator) can tell how big file is and tell you how for through you are as a percentage; with `cat bigfile | pv | whatever`, it has no idea (unless you add a flag to tell it). Also, `cat bigfile | head` will end up killing cat with a SIGPIPE signal after head exits; if you're using something like "Unofficial bash strict mode" [1], this will cause your script to exit prematurely.

Another sometimes-important difference is that if there are multiple input files, `somecommand file1 file2 file3` can tell what data is coming from which file; with `cat file1 file2 file3 | somecommand` they're all mashed together, and the program has no idea what's coming from where.

In general, though, I think it's mostly a matter of people's expertise level in using the shell. If you're a beginner, it makes sense to learn one very general way to do things (`cat |`), and use it everywhere. But as you gain expertise, you learn other ways of doing it, and will choose the best method for each specific situation. While `cat |` is usually an ok method to read from a file, it's almost never the best method, so expert shell users will almost never use it.

[1] http://redsymbol.net/articles/unofficial-bash-strict-mode/

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

#314

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.

As a scientist who cares about reproducibility, the big difference between the "useless cat" and providing the input file name on the command line is that, in the latter case, the program can capture that file name and reproduce it. That is harder when using stdin.

Many of my programs and scripts start output with the line: # cmd arg1 arg2 arg3 ...

and simply echo back lines that start with '#'. That way, I have an internal record of the program that was run and the data file that was read (as well as previous parts of the analysis chain).

And, 'R' ignores lines starting with '#', so the record is there, but does not affect later analyses.

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

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

I find that the `pbpaste | something | pbcopy` idiom is common enough that it's worth having a shell function for it:

  pbfilter() {
      if [ $# -gt 0 ]; then
          pbpaste | "$@" | pbcopy
      else
          pbpaste | pbcopy
      fi
  }       

Then you can use something like `pbfilter json_pp` or `pbfilter base64 -d` or `pbfilter sed 's/this/that/'` or whatever.

This version also can also act as a plain-text-only filter. If you just use `pbfilter` with no argument, it'll remove any formatting from the text in the pasteboard, leaving just straight plain text.

It does have a some limitations, though: you can't use it with an alias, or pipeline, or anything complex like that. The filter command must be a single regular command (or function) and its arguments.

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

#316

I just freaked out my cat using `say`. I'm going to enjoy this too much.

try it out with different voices, for starters try say "process failure" -v trinoids you can find all the available voices with say -v '?' or from Accessibility>Spoken-Content>System-voice>Manage-voices

We must rejoice in this morbid voice.

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

#318

Earlier quoted context omitted.

I have a clipboard manager application called "Paste" (creative i know). Its an awesome app for a million reasons. But one thing I like is that it allows me to see and hear when my iphone copy worked. So I have it enabled so there is a sound when something goes into the clipboard. Even on my mac, I have come to rely on that audio feedback. But it has the added benefit that when I am using my phone in front of my comp…

I wonder if it's this one: https://apps.apple.com/us/app/paste-clipboard-manager/id9678... I've noticed that more and more apps on both macOS and iOS sniff the clipboard contents and randomly clobber it. I usually notice it in apps like Sourcetree, where I'll click something or do a certain action and suddenly I can't paste anymore. I even get a feel for it, like my mind detects the pattern that empties the clipboard…

I think iOS now has per-app permissions/notifications around clipboard reads.

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

#319

`open` is one I use all the time. I love that simple command. alias tab='open . -a iterm' alias phpstorm='open -a "PhpStorm"' alias smerge='open -a "Sublime Merge"' etc. I use those more than I do the Open/Recents dialogs in the respective apps.

To open a new finder window in the current directory in a terminal:

    alias finder='open .'

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

#320

The say command has one of my favorite pieces of that famous Apple polish. If you type `say os x`, it'll actually speak "oh es ten".

It says "oh es ex" for all variations I've tried

Interesting. Says 'OS 10" on my Ventura 13.4 macbook.
Post reply on HN