Live data from Hacker News

macOS command-line tools you might not know about

saurabhs.org

211–220 of 454 posts

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

#211
post #191

Earlier quoted context omitted.

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

The “useless cat” meme needs to die. Everyone is aware that most commands accept a file argument, but looking up the arguments and their ordering is annoying and using cat for things like this is just fine.

The redirect always works though - that is not a program argument, that is handled by the shell. Apparently not everyone is aware of that.

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

#212
post #189

Earlier quoted context omitted.

> cat textfile.txt > looks like its comma delimited. Interesting; why wouldn't you use `head`? Who knows how big textfile.txt is?

`file` will tell you too

Won't tell you the delimiter.

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

#213
post #189

Earlier quoted context omitted.

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?

Don't forget to pipe head into 'cat -v'... that text file could contain _anything_!

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

#214
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?

If the command is meant to stream through something really fast by using a large buffer size, then prepending a cat(1) will limit the incoming buffer size to ~4k.

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

#215

Earlier quoted context omitted.

You can lock the screen while caffeinated though.

Automatic screensaver enable after a period of inactivity is considered a fail safe control.

`caffeinate` can set assertions, the same assertions that Zoom or PowerPoint or Keynote do to stop the screen going to sleep during a meeting or presentation, the same assertions that the browsers can set during streaming video, so you absolutely can bypass whatever your admins set using `caffeinate -dmisu` which sets every assertion available.

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

#216

Earlier quoted context omitted.

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

GNU and BSD grep both default to "basic" regular expressions and both have the `-E` switch to use "extended" expressions.

Last time I used macOS (which was 6 years ago) there was no extended expressions, or the regex syntax was limited. I forget (again, haven't used an apple product in years)

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

#217

Earlier quoted context omitted.

I can’t help but ask, why “,notify” and not just “notify”?

I name all my personal programs prefixed by the comma. I learnt it from someone on lobste.rs. No Unix utilities use the prefix in their name and it is a valid filename. So I can type , and I am sure it's my program and I'm not running something else and it'll autocomplete among my list of programs.

This is a very cool idea, I always hesitate to add a lot of aliases to my zshrc since I never want to step on any toes.

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

#219
post #203

Earlier quoted context omitted.

They avoid an unnecessary invocation of the cat executable. Instead, they open a file descriptor and pass that. Tiny difference but there you go.

I teach shell scripting. Cat invocations are cheap and help learners understand and keep clear where input is coming from, and where it is going. There are no awards or benefits to reducing the number of lines, commands invoked, or finding the shortest possible way to perform a task in a script. There are plenty of detriments to reading and understanding though when we try to obfuscate this to save 1ms of execution t…

I 100% agree with you. My only defense of OP is that `<` is something tends to be forgotten. Like everyone else in this thread I go to `cat` first for things like this. But sometimes I forget that even `<` exists, and the callout is a nice reminder.

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

#220
You can use sips together with iconutil to generate a complete .icns file for your app from a single 1024 by 1024 PNG without any third party software:

    mkdir MyIcon.iconset
    cp Icon1024.png MyIcon.iconset/icon_512x512@2x.png
    sips -z 16 16     Icon1024.png --out MyIcon.iconset/icon_16x16.png
    sips -z 32 32     Icon1024.png --out MyIcon.iconset/icon_16x16@2x.png
    sips -z 32 32     Icon1024.png --out MyIcon.iconset/icon_32x32.png
    sips -z 64 64     Icon1024.png --out MyIcon.iconset/icon_32x32@2x.png
    sips -z 128 128   Icon1024.png --out MyIcon.iconset/icon_128x128.png
    sips -z 256 256   Icon1024.png --out MyIcon.iconset/icon_128x128@2x.png
    sips -z 256 256   Icon1024.png --out MyIcon.iconset/icon_256x256.png
    sips -z 512 512   Icon1024.png --out MyIcon.iconset/icon_256x256@2x.png
    sips -z 512 512   Icon1024.png --out MyIcon.iconset/icon_512x512.png
    iconutil -c icns MyIcon.iconset
As a bonus, generate .ico with ffmpeg:

    ffmpeg -i MyIcon.iconset/icon_256x256.png icon.ico
Incidentally, does anyone know enough about the way sips scales PNGs to confirm that it makes sense to create the 16px version straight from 1024px, as opposed to basing it off 32px (and all the way up)? I.e., is it better to downscale in fewer steps (as currently) or in smaller steps?
Post reply on HN