Useful built-in macOS command-line utilities
https://weiyen.net/articles/useful-macos-cmd-line-utilities afconvert(1) - an audio file format converter, which includes Apple's superior AAC codec from the Core Audio framework
diskutil(8) - tons of tools for fixed and removable storage
Examples: afconvert in.wav -o out.m4a -q 127 -s 2 -b 160000 -f m4af -d 'aac '
mb=300; diskutil eraseVolume APFS myramdisk `hdiutil attach -nomount ram://$((mb*2048))`
hear (macOS speech recognition and dictation via the command line)
See: https://sveinbjorn.org/hear(Uses built-in macOS capabilities for transcription from audio to text.)
open -n file.pdf : opens new instance of Preview application which is useful if you want to open the same file twice (for example to look at different pages at once).
caffeinate -d : prevents display turning off, useful if you want to look at display without moving mouse.
Docs are at https://ss64.com/mac/diskutil.html
https://terminaltrove.com/categories/macos/
You might find one you've never heard of that is useful! :)
"...a menu driven program which partitions disks using the standard
Apple disk partitioning scheme described in "Inside Macintosh: Devices".
It does not support the Intel/DOS partitioning scheme[.]"
qlmanage -p $argv >/dev/null 2>&1
For me, increasing the number of icons in the launcher grid was very useful.
After running these three commands, the size of the Launcher will be set to 13x8 apps:
defaults write com.apple.dock springboard-columns -int 13
defaults write com.apple.dock springboard-rows -int 8
defaults write com.apple.dock ResetLaunchPad -bool TRUE; killall Dock
In general, a lot of parameters of different applications can be changed via command `defaults`To get a complete list of parameters, you can execute
defaults read
(shift+command+K) or Menu 'Shell' -> 'New Remote Connection...'
opens a SSH, S(FTP), TELNET connection manager window!
For example I'm having a problem that comes and goes now and then where Bluetooth audio is 300 ms delayed compared to the video playback everywhere except in Youtube on Safari, very strange. It's good for a few months then suddenly it becomes unusable, then back to zero sync delay after a few months.
I was thinking this might be related to CODEC selections etc or some hidden setting that might get changed which we normally aren't allowed to determine :)
(btw I know there is a difference between latency and synchronization - latency might be unavoidable but video sync should always be able to compensate - I got curious on how exactly that works, where in the app / SDK / OS pipeline does the a/v sync happen on a Mac?)
To scare your teammates when you are logged in remotely optionally with
$ osascript -e "set volume output volume 100"
sudo powermetrics
* atuin - TUI for shell history, backed by SQLite - https://github.com/atuinsh/atuin
* LSD (LSDeluxe) - rewrite of `ls` - https://github.com/lsd-rs/lsd
* ripgrep - https://github.com/BurntSushi/ripgrep
* fzf - command-line fuzzy finder that enhances file search, command history search, and more - https://github.com/junegunn/fzf
Notes:
- To get pretty extra file/folder symbols with LSD, you'll probably need to install some special fonts.
- You can use `fzf` and `ripgrep` together.
You can also change voices with -v. My favorite is "cellos" since it sings to you.
/usr/bin/plutil -extract your.key.path raw -o - - <<< "$jsoninput"
(obviously, less useful now that `jq`is built in)
https://www.opengroup.org/openbrand/register/
These are all guaranteed to work:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/
(I may not have linked to the precisely correct version.)
$> long_running_command && say "Witness me, for I am done"
But I don’t have uuidgen!
Say you've got a directory that has scripts or data files related to some thing you do. For example I've got several scripts that I use when I scan books with my book scanner. I only need these when doing book scanning stuff so don't want to put them somewhere in $PATH. I want to be able to easily run them from scripts that aren't in that directory, but I don't want to hard code the path to that directory.
Solution: in the directory with the book scanning scripts I make a file named ID that contains a unique string. I currently use 16 byte random hex strings [1].
I have this script, named find-dir-by-ID, somewhere in $PATH:
#!/bin/zsh
ID=${1:?Must specific ID}
IDSHA=`echo $ID | shasum | cut -d ' ' -f 1`
mdfind $ID 2>/dev/null | grep /ID | while read F; do
FSHA=`shasum $F | cut -d ' ' -f 1`
if [ $IDSHA = $FSHA ]; then
dirname $F
exit 0
fi
done
exit 1
If some script wants to use scripts from my book scanning script directory, it can do this: SCRIPT_DIR=`find-dir-by-ID 54f757919a5ede5961291bec27b15827`
if [ ! -d $SCRIPT_DIR ]; then
>&2 echo Cannot find book scanning scripts
exit 1
fi
and then SCRIPT_DIR has the full path to the scanning script directory.The IDs do not have to be hex strings. If I'd thought about it more I probably would have made IDs look like this "book-scanning:54f757919a5ede59" or "arduino-tools:3b6b4f47bf803663".
[1] here's a script for that:
#!/bin/sh
N=${1:-8} # number of bytes
xxd -g $N -c $N -p -l $N < /dev/urandom
/System/Library/PrivateFrameworks/Apple80211.framework/Versions/A/Resources/airport -s
I set a shell alias so I can just do `airport -s`. I've no idea why this is hidden away inside some framework and not in a directory which is in the normal path, but there you go.
locate
https://ss64.com/mac/locate.htmllocate searches a database for all pathnames which match the specified pattern. The database is recomputed periodically, (about once a week) and contains the path-names of all files which are publicly accessible.
Sigh. These are shell commands, not "Bash commands".
Very useful.
I use it most often for pulling lat lon data from photos.
As part of the OS, Keychain suffers from the same sorts of sharp edges as using a built-in interpreter. An alternative is to use a password manager. Below is an example of the tools available in one.
https://developer.1password.com/docs/cli/get-started/#step-1...
upgrade_macos() {
softwareupdate --list
softwareupdate --download
softwareupdate --install --all --restart
}