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.
alias qt='open -a "quicktime player"'
alias vlc='open -a "vlc"'
My poor workaround is to use osascript: `tell application "System Events" to set frontmost of process "Finder" to true`
open -a <GUI Application> <File>
Handy for distinguishing between editing and consuming media.
Not mine (found online years ago), but here's the opposite. `cd` into the frontmost Finder window:
cd "$(osascript -e 'tell app "Finder" to POSIX path of (insertion location as alias)')";
Standard apps usually just need the name, like Finder and Safari but you can also specify the path "/Applications/DifferentFinder.app"
It is just the first time the .DS_Store file is needed is often when the folder is touched by Finder.
I guess you could do that centrally with some sort of database but that would open another can of worms; and most importantly you wouldn't be able to transfer a folder and keep its Finder presentation intact.
Nowadays it's not as useful because of the App Store but when software was only released as .dmg images, it became expected to open a nice layout with graphics presenting the app and a shortcut to the App folder that you would drag'n'drop the app bundle to.
This presentation relies of .DS_Store to work.
There are some other use cases like that, it all comes down to a simple fact: Apple has always cared a lot more about how things look than Microsoft ever did, this is a perfect example.
Of course, they could rethink the whole thing but the point is that it's a legacy thing and at this time it's not worth dedicating much ressource to a solve problem just to remove some mostly invisible files (on UNIXs). It's really easy to have scripts to cleanup for sharing to outside world, even some zip utilities do that automatically.
It can be annoying but it's really not a big deal, I doubt they could come up with something much better while still preserving the functionality and not making another complicated/convoluted proprietary folder format that wouldn't transfer any better to Windows...
open .
unless you've reconfigured something else to open directories, which most people haven't.I think Windows is right in that matter...
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
afconvert -v -s 3 -f m4bf filename.mp3
Not gonna lie, I missed this because I thought it was related to macOS SIP, System Integrity Protection. Which is something I am deeply uninterested in.
sips -s format png photo.HEIC --out photo.png
or resizing: sips -z 300 600 original.jpg --out new.jpg
Very useful.
-u Create an assertion to declare that user is active.
afconvert -v -s 3 -f m4bf ....mp3
/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.
WARNING: The airport command line tool is deprecated and will be removed in a future release. For diagnosing Wi-Fi related issues, use the Wireless Diagnostics app or wdutil command line tool.
"...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[.]"
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
That could work fine, but generally the directories I've used this on are directories that I want to have somewhere else, and with a reasonable name. Usually the directories came first and various other things in fixed relative positions were using them, and then later I wanted to use them from elsewhere and added the ID.
I suppose ~/well-known/stuff/54f757919a5ede5961291bec27b15827 could by a symbolic link to the original.
The mdfind approach does have the advantage that if I reorganize things and move the directory it keeps working.
Downlink: 884.856 Mbps, 198 RPM - Uplink: 13.238 Mbps, 198 RPM
whereas speedtest (whether to the official speedtest server OR a friend's home server in their basement!) gives ~700 Mbps uplink.
networkQuality -s
That's a more apples to apples comparison to speedtest.net; Separate upload and download tests.(shift+command+K) or Menu 'Shell' -> 'New Remote Connection...'
opens a SSH, S(FTP), TELNET connection manager window!
It's quite a good VNC client, too.
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?)
I guess filtering the streaming log entries in the Console app gives some info.
To scare your teammates when you are logged in remotely optionally with
$ osascript -e "set volume output volume 100"
/usr/bin/plutil -extract your.key.path raw -o - - <<< "$jsoninput"
(obviously, less useful now that `jq`is built in)
; which jq
/usr/bin/jq
; jq
jq - commandline JSON processor [version 1.6-159-apple-gcff5336-dirty]
Wow. When did `jq` start shipping by default? TILGlad to spread the good word ;)
Hold up, what?
function batt-info() {
echo
system_profiler SPPowerDataType | grep Wattage | cut -c 7-
echo
pmset -g batt
}
if [[ "$(uname)" == "Darwin" ]]; then
clip() {
[ -t 0 ] && pbpaste || pbcopy
}
else # assume linux if not macos
clip() {
[ -t 0 ] && xclip -o -selection clipboard || xclip -selection clipboard
}
fi
Also, falling back to using oh-my-zsh functionality.
$ pbpaste | jq | pbcopy
Then I can paste it into whatever text editor I want and it's all nice & pretty-printed for me.
Bonus is that I don't have to change the command at all, just copy the minimized JSON to the clipboard (say from DBeaver, for example), then hit the 'up' arrow and enter.
[1]: https://github.com/DvdGiessen/dotfiles/blob/2c02332b4a657690... [2]: https://github.com/DvdGiessen/dotfiles/blob/2c02332b4a657690...
I use it most often for pulling lat lon data from photos.
upgrade_macos() {
softwareupdate --list
softwareupdate --download
softwareupdate --install --all --restart
}
sudo powermetrics
coreaudiod is using very high CPU at 111.90 ms/s
I'm on a 16" M1 Macbook Pro 16 gig.
Maybe they are using it "wrong" but Apple Music isn't exactly light on ressource either...
Docs are at https://ss64.com/mac/diskutil.html
gdisk /dev/disk0
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...
https://www.reddit.com/r/mac/comments/18ez5b0/why_disk_utili...
It's a bit sad because the whole point of Apple was, "we are not IBM" after the PC got its start. They are very much IBM now.
As for ZFS, it has its use for sure (servers) but it's very heavy on ressource and very complex. I don't think it's just because of the buyout of Sun, overall, it's just overkill for a personal computer; and since Apple completely left the server market, even for SMBs, there is no real reason to push for it.
In the end it's not really about any filesystem, the problem is mostly that Apple is not a user focused company as much as it used to be. They could make better technical UI/Apps/Solutions but they don't care that much, they make too much money selling gadgets (those are good but really not the same thing as "proper" computers).
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.)
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...
> hear not found
macOS 15.1
> hear is a command line interface for the built-in speech recognition capabilities in macOS
Have you gone through the installation process? https://github.com/sveinbjornt/hear?tab=readme-ov-file#insta...
But I don’t have uuidgen!
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...
* 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.
I still get a ton of mileage from reading the macOS How-to page https://ss64.com/mac/syntax.html
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.
Your better bet on MacOS is to use `mdfind -name ....`
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.)
Sigh. These are shell commands, not "Bash commands".
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
$> long_running_command && say "Witness me, for I am done"
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))`
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
Way back then (iPod era), I made an exposé for a science exam (small paper), proving that AAC was indeed better than MP3 both subjectively and objectively at most bitrates. This is how I got introduced to Fourier transforms and the likes; it was very interesting to see that you can literally "see" the difference in quality on the encoded waveform output.
But I just used the default encoders on the Mac and I didn't think about going in deep into encoder comparisons at the time. Does it matter that much? From what I know, it just about properly programming a math spec, with some tricks but I wonder if that makes that much of a difference.
In any case, above 256kbps it takes a very skilled listener to correctly identify encoded music. Apple has some useful tools for that, particularly AU Lab that allows you A/B testing of tracks with on-the-fly encoding. https://www.apple.com/apple-music/apple-digital-masters/
> Does it matter that much? From what I know, it just about properly programming a math spec, with some tricks but I wonder if that makes that much of a difference.
It does matter a lot and the difference can be staggering. Producing the audio bitstream is a case of both effectively analyzing the original input and programmatically expressing the waveform as correctly and as efficiently possible. Two excellent examples: the old MP3 encoder Xing, which compared to LAME produces very poor material even at higher bitrates, and one of the earliest open-source AAC encoders, FAAC, which also renders a very poor product. A lot of "early adopters" got bitten by FAAC and many of them still stubbornly cling to the misunderstanding that AAC is a worse format than MP3.
Incorrect. The specification only concerns the bitstream and the decoding. Encoders are free to do whatever they want, as long as they produce a valid bitstream.
Of course, the implementations are going to have varying performance depending on code quality/optimisations but that's a given.
Edit: some other poster gave some cues to my question. I guess you can do some trickery by decomposing the waveform before encoding and recomposing it.
I'll read more on the specs.
If you're wondering how one implementation of an audio codec could be superior to others — mostly, it's because any lossy audio codec has an encoding phase called "psychoacoustic compression", where each implementation of the codec is free to do whatever it likes to "simplify" the waveform in some way (most easily pictured: by taking a Discrete Cosine Transform of the waveform, and then quantizing / convoluting some parts of the frequency space. Like what JPEG does to discard information from the chroma channels.)
IIRC, rather than blunt-force quantization, Apple's AAC encoding does clever things (akin to the instrument separation done to audio in Melodyne) to split the waveform into "features", and then discards information in such a way that the features' separability is maintained (i.e. it doesn't become harder to "pick out" any given "sound" from the audio.)
afconvert -- Audio File Convert
diskutil -- Modify, verify and repair local disks.
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.
Love those type of OG Mac indie software.
I prefer to encode with afconvert on the command line because it gives me a few more options for tweaking things, that I don't have access to in iTunes (or "Music" as it's called these days). Additionally, I use a simple shell script that handles all of it when for example ripping a whole CD.
qlmanage -p $argv >/dev/null 2>&1
I do this with man pages but it opens up in a full Preview window, not QuickLook.
qlmanage -p <(man man) >/dev/null 2>&1
0 - https://www.gnu.org/software/bash/manual/html_node/Process-S... (it works in zsh too, but bash manual explains this feature more clearly)You can also change voices with -v. My favorite is "cellos" since it sings to you.
It also knows how to say numbers up into the trillions but not more than that (although I feel like it used to).
I hacked together a little script for demo recording like:
START_FROM="$1"
STARTED=0
function transcript() {
ID="$1"
TO_SAY="$2"
if [[ ...STARTED || START_FROM && ID... ]]; then
STARTED=1
say "$TO_SAY"
fi
}
transcript "STEP001" "This is a test"
transcript "STEP001b" "of the emergency broadcast system"
transcript "STEP002" "This is only a test, if this was ..."
transcript "STEP003" "...etc..."
...and then I have a hardcoded `--output` which will then change the invocation to `say -o "$ID.wav" "$TO_SAY"` and output audio files.That way I can iterate on voiceover scripts, eg: `./demo-script "STEP002"` => `./demo-script --output`
It's really helpful for iterating on pronunciations, eg: `transcript "STEP005" "In case of Four Hundred and Four errors..."`, I can just "skip to" and iterate against that line (and subsequent ones), or "skip back" and hear it in more of a flowing context.
...even if I don't end up using the `say`-generated audio, having a transcript (and even pacing) that I can just read through with my own voice is super helpful.
https://terminaltrove.com/categories/macos/
You might find one you've never heard of that is useful! :)
Install vscode on Linux and have fun with it hijacking opening directories. Which is easy enough to fix (with a bit of know how) or work around but annoying.
MacOS is far from perfect but open always doing what I expect is a good example of what Apple did well.
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.
networksetup was one of my favourites as well as du and caffeinate.
The 'security' command is new to me so thanks!
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)