Live data from Hacker News

macOS command-line tools you might not know about

saurabhs.org

281–290 of 454 posts

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

#281
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 love this flow! Such a powerful and clean way to solve text issues. # This will remove Windows double-spaced empty lines from your copy/paste buffer alias winlines="sed '/^$/{$!{N;s/\n//;};}'" # pbw = [P]aste [B]uffer to fix [W]indows line endings alias pbw="pbpaste | winlines | pbcopy" Also - if you want `pbpaste` and `pbcopy` on Linux... # imitate MacOS's paste buffer copy/paste: alias pbcopy='xsel --clipboard --…

There's `wl-copy` and `wl-paste` for Wayland users too, via https://github.com/bugaevc/wl-clipboard

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

#283
I like to hide all icons or folders on my Desktop when I need to be more productive or when I'm presenting. This can be done with:

  # hide desktop icons and folders
  defaults write com.apple.finder CreateDesktop 0
  killall Finder # restarting Finder is required

  # unhide desktop icons and folders
  defaults write com.apple.finder CreateDesktop 1
  killall Finder # restarting Finder is required


I made myself a convenient bash alias for this which lets me simply toggle the desktop on and off Here is a gist: https://gist.github.com/berndverst/6f58c0d6aedddb6c06c23e57d...

  toggledesktop () {
    if [[ $(defaults read com.apple.finder CreateDesktop) -eq "0" ]]
    then
        export SHOWDESKTOP=1;
        echo "Unhiding Desktop icons"
    else
        export SHOWDESKTOP=0;
        echo "Hiding Desktop icons"
    fi
    defaults write com.apple.finder CreateDesktop $SHOWDESKTOP
    killall Finder
  }

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

#284

Years ago, I wrote a script to find something in a big blob of data and to alert me when it was done, I added a “say ” type phrase upon completion. I forgot about it and went to bed and was jolted awake hours later by what was clearly an “intruder” speaking to his accomplice, in my home office. Quite the relief when I realized what happened.

I like to use the "research complete" sample from StarCraft for this.

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

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

Also a fun one to combine with `open` if you have a bunch of web URLs to open

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

#287
A lot of macOS behavior can be toggled by modifying the system component defaults.

For example, turn off autohiding of the Dock from commandline:

  defaults write com.apple.dock "autohide" -bool "false" && killall Dock
Include the date in screenshots you take:

  defaults write com.apple.screencapture "include-date" -bool "true"
Here is handy website which documents many of the defaults and their purpose: https://macos-defaults.com/#%F0%9F%99%8B-what-s-a-defaults-c...

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

#288
post #127
post #121

Earlier quoted context omitted.

Another frequent use I have, applying random diffs with git: git diff | pbcopy pbpaste | git apply

You can also use `git format-patch` and `git am` if you want to apply the same commit to multiple repos, a use-case I sometimes I have.

I should use `git format-patch` instead of creating a mock draft PR (which I end up deleting) and modifying the URL to add `.patch` and then downloading the patch file haha. `git format-patch` would probably be faster :)

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

#289

afconvert(1) lets you convert between various audio formats - most noteworthy is that it gives you access to Core Audio's superior AAC encoder without having to use iTunes/Music: afconvert music.wav -o music_160kbps_aac.m4a -b 160000 -q 127 -s 2 -f m4af -d 'aac ' lipo(1) lets you operate (replace/extract/thin/etc) on executables and libraries to tailor their supported architectures: lipo -thin arm64e -output

Also, using hdiutil(1) and diskutil(8) to create a RAM-disk:

  # 500 megabytes disk image
  mb=$((500*2048))
  diskutil eraseVolume ExFAT my_ramdisk `hdiutil attach -nomount ram://$mb`

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

#290
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 have a script always running that polls for youtube URLs using pbpaste and runs yt-dl

then just highlight any youtube link and COPY

later when I have time, I can use quicklook to browse directory of youtube videos.

Post reply on HN