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
Mostly I use XLD (https://tmkk.undo.jp/xld/index_e.html) for audio conversion (as I'm mostly converting from .BIN + .CUE to "iTunes Plus" AAC for uploading to iTunes Match); but my understanding is that under the covers it's mostly just using afconvert (or whatever the system-framework equivalent of it is.)
So if your needs are just "one audio file in, one audio file out, and let me tell you exactly what it should look like", then afconvert is probably what you want.
Oh wow! A while back I ripped some concert audio from Youtube, but it was too large for me to sync using my `iTunes Match`. I've been too lazy to figure out how to downsample it juuuuust enough. But it looks like this works right out of the box
"superior" ...
It looks silly to include such a judging adjective in the description of a comman line utility. I don't need "subtle" Apple ads on the command line. And aac is about the last format I would choose, encoding my audio in.
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.
You can use it to pass a pid to keep the computer awake until that process completes. I use it for longer-running scripts that I don't want interrupted
> (Uses built-in macOS capabilities for transcription from audio to text.)
Question (to self, currently researching)... Which capabilities? Released when? I ask because Apple Intelligence has expanded the use of audio transcription features.
Answer: `hear` uses SFSpeechRecognizer [1] which has been available since macOS 10.15. I'm not yet sure how it relates to Apple Intelligence transcription services.
Note: "speech recognition is a network-based service" which perhaps suggests Apple Intelligence (the marketing term, not an Apple Developer term, I don't think) uses it as well
Disk Utility used to be excellent, a model of how an app should be.
But then they rewrote it in Swift and now it's just bad.
Apple promotes Swift heavily but the results are not really encouraging.
I don't think the "so-so" results are entirely because of Swift (probably due to newer, less battle tested software and also newer/younger devs) but still the fact is, all the not-so-great new software from Apple came with Swift rewrites, hard to not make a connection...
If you want the least useful macOS commandline utility, 'pdisk' is:
"...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[.]"
I found a tool of mine submitted by someone else on the site (pleasant surprise!) and I want to update the description and add a more recent/better image. How would I do that?
As they seem to have removed Bluetooth Explorer and all ways to get diagnostic info about the bluetooth system and/or change codecs and settings, does anybody know any good cmdline ways in later mac osxes to do the same?
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?)
nc(1) - netcat, arbitrary TCP and UDP connections and listens
networkQuality - Speed test + network stress tool.
system_profiler(8) - Useful way to grab extensive system information in shell scripts.
wdutil(8) - wdutil provides functionality of the Wireless Diagnostics application in
command line form.
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
And for those of us who have to support macOS users:
sw_vers (to display the version/build of macOS),
dsenableroot (to enable the root user), and
say "phrase" (useful for freaking out users over a remote SSH connection)
plutil. Maybe not that useful to a lot of people but I have been going through and collecting bookmarks and Safari bookmarks are binary files. plutil is a means of converting the binary property file to a json or xml file.
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.
What I'm really missing still is a cli to iCloud stored passwords. AFAIK 'security' cli can't access the credentials stored in the cloud. This would be helpful to store secrets outside of git but would still allow scriptable access to them similarly as 1password cli 'op' has.
Does anyone remember the shortcut that brings up a list of currently available keyboard shortcuts for the current app? It may not be built-in, in which case it was a free utility.
Looks like a lot of these have linux equivalents that could be aliased. I wonder if anyone's made a set of those for regular macos users who occasionally use something else.
> If you store your secrets in the Keychain (and you should!)
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.
locate 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.
I just remembered at a previous job where we were always paired and used team rather than individual iMacs for development that as a prank I ssh’d into the other iMac from my team and periodically would run open on a random URL which caused a Safari window to mysteriously pop up their system.
pbcopy and pbpaste are among my top commandline utilities. If you are running linux in WSL, you can add the following to you path to recreate their functionality:
# pbpaste
#!/bin/bash
# Adapted from https://www.techtronic.us/pbcopy-pbpaste-for-wsl/
powershell.exe Get-Clipboard | sed 's/\r$//' | sed -z '$ s/\n$//'
exit 0
and
# pbcopy
#!/bin/bash
#Adapted from https://www.techtronic.us/pbcopy-pbpaste-for-wsl/
<&0 clip.exe
exit 0
There is also 'say' which is great if you need to step away from a long running command, in a similar fashion to ringing the terminal bell but with more context.
A couple more:
Examples:Mostly I use XLD (https://tmkk.undo.jp/xld/index_e.html) for audio conversion (as I'm mostly converting from .BIN + .CUE to "iTunes Plus" AAC for uploading to iTunes Match); but my understanding is that under the covers it's mostly just using afconvert (or whatever the system-framework equivalent of it is.)
So if your needs are just "one audio file in, one audio file out, and let me tell you exactly what it should look like", then afconvert is probably what you want.
> afconvert
Oh wow! A while back I ripped some concert audio from Youtube, but it was too large for me to sync using my `iTunes Match`. I've been too lazy to figure out how to downsample it juuuuust enough. But it looks like this works right out of the box
"superior" ... It looks silly to include such a judging adjective in the description of a comman line utility. I don't need "subtle" Apple ads on the command line. And aac is about the last format I would choose, encoding my audio in.
There's also afplay - Audio File Play (plays an audio file to the default audio output). Can play all audio formats supported by CoreAudio.
How does that compare with ffmpeg? The arguments seem about the same.
> afconvert
See also XACT[1]. It's a macOS GUI, but it's nerd-friendly.
[1] http://xact.scottcbrown.org
Few additions.
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.
Another useful caffeinate tip is the `-w` option.
You can use it to pass a pid to keep the computer awake until that process completes. I use it for longer-running scripts that I don't want interrupted
I use this all the time:
open -a <GUI Application> <File>
Handy for distinguishing between editing and consuming media.
open -a is nice, i use it with alias, ex:
`caffeinate -disu` is the best combination (that is, enable all options): your laptop won't go to sleep, won't dim the screem etc.
open -a "Finder" . - open Finder in the current directory.
Standard apps usually just need the name, like Finder and Safari but you can also specify the path "/Applications/DifferentFinder.app"
That's one of macOS pitfalls: the inability to open 2 instances of the same app, simply using the default GUI is annoying sometimes.
I think Windows is right in that matter...
Does `open` give focus? It used to, but since a few releases ago the app opens in the background, which is pretty annoying.
My poor workaround is to use osascript: `tell application "System Events" to set frontmost of process "Finder" to true`
Also, `cd .` to open the current directory in a Finder window.
Not mine (found online years ago), but here's the opposite. `cd` into the frontmost Finder window:
caffeinate -d is incredibly useful for work... uh reasons
I would like to also recommend the app:
See: https://sveinbjorn.org/hear(Uses built-in macOS capabilities for transcription from audio to text.)
Its open source GitHub repo at https://github.com/sveinbjornt/hear
Man page at https://sveinbjorn.org/files/manpages/hear.1.html
> (Uses built-in macOS capabilities for transcription from audio to text.)
Question (to self, currently researching)... Which capabilities? Released when? I ask because Apple Intelligence has expanded the use of audio transcription features.
Answer: `hear` uses SFSpeechRecognizer [1] which has been available since macOS 10.15. I'm not yet sure how it relates to Apple Intelligence transcription services.
Note: "speech recognition is a network-based service" which perhaps suggests Apple Intelligence (the marketing term, not an Apple Developer term, I don't think) uses it as well
[1][ https://developer.apple.com/documentation/speech/sfspeechrec...
I thought I recognized the name of the developer! The person that brought us Platypus! Nice.
> which hear
> hear not found
macOS 15.1
The terminal version of Disk Utility is actually much better than the GUI (it doesn't hang and the app is glitchy.
Docs are at https://ss64.com/mac/diskutil.html
Disk Utility used to be excellent, a model of how an app should be. But then they rewrote it in Swift and now it's just bad.
Apple promotes Swift heavily but the results are not really encouraging. I don't think the "so-so" results are entirely because of Swift (probably due to newer, less battle tested software and also newer/younger devs) but still the fact is, all the not-so-great new software from Apple came with Swift rewrites, hard to not make a connection...
`pdisk` might be more convenient if you've worked with `gdisk` on ArchLinux
https://manpagez.com/man/8/pdisk/
Or "man diskutil"
This article contains links to https://ss64.com/ , which is an amazing resource that I wish I'd known about sooner!
100% That's why I made it a point to share that page.
I still get a ton of mileage from reading the macOS How-to page https://ss64.com/mac/syntax.html
Thanks for the kind words, I'll be scanning this thread to see if there's anything new that I've missed.
If you want the least useful macOS commandline utility, 'pdisk' is:
Although not built in, we have a list of easy to install command-line utilities for macOS.
https://terminaltrove.com/categories/macos/
You might find one you've never heard of that is useful! :)
Kinda related: does anyone else regularly finds CLI tools, installs them and never ever even call them once?
This looks like a list of cross-platform command line tools. What about it is Mac-specific?
I found a tool of mine submitted by someone else on the site (pleasant surprise!) and I want to update the description and add a more recent/better image. How would I do that?
Related - https://news.ycombinator.com/item?id=36491704 "macOS command-line tools you might not know about"
It's probably been written about a lot of places already.
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:
In general, a lot of parameters of different applications can be changed via command `defaults`https://macos-defaults.com/
To get a complete list of parameters, you can execute
$ say Hello
To scare your teammates when you are logged in remotely optionally with
$ osascript -e "set volume output volume 100"
Not a command, but a little known feature of the Terminal app:
(shift+command+K) or Menu 'Shell' -> 'New Remote Connection...'
opens a SSH, S(FTP), TELNET connection manager window!
As they seem to have removed Bluetooth Explorer and all ways to get diagnostic info about the bluetooth system and/or change codecs and settings, does anybody know any good cmdline ways in later mac osxes to do the same?
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?)
More:
TinkerTool provides a GUI that runs some useful commands under the hood
https://www.bresink.com/osx/0TinkerTool/download.php
One-liner for previewing a file with Quick Look. I aliased this to `ql` :)
It misses the most important of them all, if you are used to copy content to usb drive for reading on a multimedia player : dot_clean -m
To find what causes your laptop drains its battery, you can use
I'll add `plutil` to the list. It's great for reading plist files, but did you know it can parse json too?
/usr/bin/plutil -extract your.key.path raw -o - - <<< "$jsoninput"
(obviously, less useful now that `jq`is built in)
Looks like the site's down.
https://archive.is/kGmn6
sips https://ss64.com/mac/sips.html
I've never heard of networkQuality, that's seems like quite a useful tool.
Here's a handy use I've found for mdfind.
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:
If some script wants to use scripts from my book scanning script directory, it can do this: 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:
There is also pmset which is very useful (since macOS doesn't give a UI counterpart) https://support.apple.com/en-am/guide/mac-help/mchl40376151/...
My non-built-in CLI utility recommendations, none of which are macOS specific:
* 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.
pbcopy and pbpaste are handy, for a version that works over ssh connections there is osc: https://github.com/theimpostor/osc
And for those of us who have to support macOS users:
Great tip about the `security` command, a new one for me.
I got this trick from someone on the Internet:
$> long_running_command && say "Witness me, for I am done"
A fun easter egg in the "say" command is that "OS X" is said as "Oh Ess Ten".
You can also change voices with -v. My favorite is "cellos" since it sings to you.
Since Apple spent so much effort in getting certified:
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.)
plutil. Maybe not that useful to a lot of people but I have been going through and collecting bookmarks and Safari bookmarks are binary files. plutil is a means of converting the binary property file to a json or xml file.
https://keith.github.io/xcode-man-pages/plutil.1.html
Want to scan the local wifi networks from the command line, and get useful information like signal strength?
/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.
mdls shows a file's metadata.
I use it most often for pulling lat lon data from photos.
What I'm really missing still is a cli to iCloud stored passwords. AFAIK 'security' cli can't access the credentials stored in the cloud. This would be helpful to store secrets outside of git but would still allow scriptable access to them similarly as 1password cli 'op' has.
Time Machine utility, examine and manipulate Time Machine backups, restore data from backups, add or remove exclusions, and compare backups
https://ss64.com/mac/tmutil.html
I maintain a more comprehensive list here: https://notes.billmill.org/computer_usage/mac_os/mac_os_comm...
But I don’t have uuidgen!
fs_usage is my favourite - find out what's thrashing the disk. (Usually Spotlight or Spark...)
Does anyone remember the shortcut that brings up a list of currently available keyboard shortcuts for the current app? It may not be built-in, in which case it was a free utility.
Looks like a lot of these have linux equivalents that could be aliased. I wonder if anyone's made a set of those for regular macos users who occasionally use something else.
> If you store your secrets in the Keychain (and you should!)
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...
I actual wrote a similar post a while back: https://www.chriswales.uk/blog/my-favourite-macos-terminal-c...
networksetup was one of my favourites as well as du and caffeinate.
The 'security' command is new to me so thanks!
locate 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.
I just remembered at a previous job where we were always paired and used team rather than individual iMacs for development that as a prank I ssh’d into the other iMac from my team and periodically would run open on a random URL which caused a Safari window to mysteriously pop up their system.
pbcopy and pbpaste are among my top commandline utilities. If you are running linux in WSL, you can add the following to you path to recreate their functionality:
andI'm sure everyone knows this, but `open` has an equivalent on Linux: `xdg-open`.
TIL: caffeinate
Very useful.
There is also 'say' which is great if you need to step away from a long running command, in a similar fashion to ringing the terminal bell but with more context.
afconvert is pretty nifty for audio format conversion.
upgrade_mac.sh: https://github.com/westurner/dotfiles/blob/develop/scripts/u... :
https://ss64.com/mac/
cliclick[1] is useful for gap-filling the AppleScript accessibility APIs when automating poorly-behaved applications.
[1] https://github.com/BlueM/cliclick
"what other operating systems might call the "clipboard""
might
shameless plug for my mac lsblk port https://github.com/JakeTrock/gosblk
pbcopy is my favorite. Almost enough to prefer a mac over my usual linux stations, but you can get that on linux easy enough.
"I like to look at the list of macOS Bash commands."
Sigh. These are shell commands, not "Bash commands".
stoked they baked in caffeine to macos, such a useful utility.
How about launchctl
[dead]