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.
I genuinely didn't know this. I would have thought I had to do the "copy as pathname" trick with a right-click while holding Option. I already knew the drag and drop feature, so this doesn't really save me time, but it's good to know another nice feature.
Also `open -R path/to/file` opens Finder in the containing directory with the file highlighted (and thus scrolled into view). I use this with a script that takes a screen recording and trims some specified seconds off the end and converts it to mp4 to be smaller when I upload into a Github PR description. Easiest to drag and drop the converted file, y'see.
Finder is pretty good, and it's handy to be able to open it from the terminal. But I find it super annoying it litters everything with .DS_Store files and there is no way to turn that off, except for external and network drives. Aside from, obviously, using a different file manager. Very un-Apple.
The .DS_Store files are not Finder specific; Apple treats everything as a file (including folders), and it exists to supply folders and the files within them with metadata.
It is just the first time the .DS_Store file is needed is often when the folder is touched by Finder.
Well those files are to keep the view/presentation settings.
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.
I don't think xattr works for folders. And you still wouldn't have the fancy presentation you can get with .DS_Store with the graphics and all that jazz.
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...
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 have thousands of old photos that preview can open, but I can’t upload them into the photo.app because the file format is wrong. I’m going to try and use SIPS to convert them all into png first and then add to photo.app. Thanks for this pointer.
sips looks really cool, thanks for pointing this out.
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.
Indeed, many applications I would expect to prevent sleeping (some audio playback ones, games, etc.) don't implement this. I assume it's a case of Apple's APIs changing over the years and not everyone catching up/caring. At one point I had downloaded Amphetamine[^1] but it is much nicer to just use the terminal here.
I was able to install a `caffeine` package with Apt on Linux. In that one the `caffeinate` command is supposed to be run with another command. While the `caffeine` command does what macOs `caffeinate` does.
That's interesting, I have never needed to do that. My Pixels have always just charged even if the lid is closed, on Intel and Apple Silicon machines. I like to travel light so I often use my laptop as a battery bank instead of carrying a seperate one.
This can be done by passing a PID. I believe there are other options, as well. (Not at my computer to look it up right now.) I haven't used those features "manually", but I have in scripts that I expect to generate long-running processes.
While it may avoid sleep, it doesn’t prevent inactivity, in my experience. For instance, my chat app at work will still show me inactive while running caffeinate. I have to do non-interactive training semi-regularly and need to interact to keep from looking like I’m away from my desk.
Doesn’t work with Slack at least. I’ve had an iTerm window running `caffeinate -disu` for years. I think it used to work and stopped working in the last few months.
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.
FWIW that appears to be soon deprecated according to MacOS 15.2:
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.
Oh, that's a pity. I'm pretty bad at keeping up to date on MacOS releases, but I should probably start figuring out `wdutil` so that my muscle memory is adapted before I've got no choice!
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[.]"
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
You mean something like having ~/well-known-stuff and under that having a 54f757919a5ede5961291bec27b15827 directory with the book scanning scripts and so on?
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.
Beyond opaqueness, which could be overcome by simply prefixing the ID with something descriptive, I guess it helps avoid creating excessively long paths that might create problem onncertain filesystems, which is rarely a problem these days, but I have been bitten by it a half dozen times over the last few years. In a couple instances causing (recoverable) data loss.
Sort of like command+k in the Finder, connects to a server. You can type in vnc://host or vnc://localhost:port... the latter is for VNC to hosts via an SSH tunnel.
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?)
Thanks.. but that github program only lists the same info you get if you command-click on the BT icon in the menu bar. It basically only shows the device name.
I guess filtering the streaming log entries in the Console app gives some info.
I've found reliably "turning on" with pmset to be hit or miss. I can't remember the gotcha I ran into if it was that you had to have your laptop lid open or something else...
Yes. If macOS is asleep or idle, pmset won't get triggered. It is best used with caffeinate.
I used it for a museum installation where every night I'd turn it off before they cut the electricity and turn it on in the morning just after electricity is switched back on: it was a way for me to be in peace with my conscience (though after some tests, the mac didn't bother getting switched off by cutting out the electricity).
since I switch between linux and macos a lot I wrote a dotfile function called "clip" that will work the same on both. nice thing is it will automatically paste if nothing is piped to it to copy so there's no need to use separate commands... although I just realized it might be nice to have a "passthrough" mode that both copies and pastes if you add this to a pipeline in order to capture some intermediate part to the clipboard
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
That's handy, thanks! `osc copy` may also take args for files to copy to the clipboard, but in the absence of that and no data on stdin it maybe should switch to paste.
At my job I have to work with a lot of JSON that's usually minimized. This command has single-handedly saved my sanity:
$ 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.
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 have a modern Mac you have very little business using `pdisk`. It is only for editing disks mapped with an “Apple Partion Map”. This is obsolete replaced in practice by GPT on modern apple machines.
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...
I have known the UI bring bad in general and I think it has more due to APFS… I used to be able to do backups but APFS is so different to everything else that at this point I wish Apple switched to ZFS but honestly that wasn’t gonna happen after the buyout of Sun to oracle .
AFPS is more complex yes, and it's sad they let down Time Machine (somewhat) with it, considering the capabilities.
But that's pretty much on point with current Apple, they would rather have you pay for iCloud "backup" than make an individual/personal solution that doesn't require subscription to their services.
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).
I wish iCloud backup was a true backup. It's really a sync, so if you accidentally rm -rf a file well you better hope you can yank out your Ethernet cable in time (or turn off wifi)
Well they do have a backup functionality, aptly named "iCloud Backup" but that's only on iOS. It's very frustrating because they are always in a rush to copy the worsts parts of iOS/iPhone for the Mac but they don't care much about bringing the good thing as long as it doesn't make them that much money.
I guess the rational is that if you have a Mac you also have an iPhone and your important data is already on your phone and thus already in a backup.
In theory they also have a file history for iCloud and you could restore files for up to 30 days, I think. I say in theory because the few times I have tried it, it was incredibly unhelpful.
But that's pretty much usual with Apple, the practice is actually very far for the theory/marketing.
> all the not-so-great new software from Apple came with Swift rewrites, hard to not make a connection...
That's a leap, but I understand your point of course. It _MIGHT_ also be said it all came from ObjectiveC experts having a first go at Swift, too. Or from groups that were run by some common set of "get it out the door" middle management types.
Yes I thought about that possibility too, but I believe most of the Objective-C old school expert are mostly gone from Apple.
It makes sense when you look at the timelines, people that were there for the early Mac days are just hitting retirement age.
Most of the executives have been replaced in one way or another, that's an indication.
And of course, Apple has a middle management problem, but that comes with Tim Cook's style; he cares about values that are just not conductive to progress and excellence. It all ends up about "getting shit done" and not caring that much if the results are actually any good.
So, they do stuff on schedule and are content with it no matter how bad it is, typical careerist behavior.
To be fair, a lot of our modern society seems to have been overtaken by these types of people, they are very popular and very "successful"; it's more noticeable at Apple because it used to be very different...
> (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
I used Platypus to make my simple command line tools accessible to coworkers who considered the command line to be "too much" to learn. I've loved that app for close to two decades.
236 comments
[ 1.6 ms ] story [ 327 ms ] threadopen -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.
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:
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...
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
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.
Very useful.
[^1]: https://apps.apple.com/us/app/amphetamine/id937984704
/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.
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:
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.
(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?)
Also: https://github.com/toy/blueutil
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)
Glad to spread the good word ;)
Hold up, what?
https://ss64.com/mac/pmset.html
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.
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
https://manpagez.com/man/8/pdisk/
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).
I guess the rational is that if you have a Mac you also have an iPhone and your important data is already on your phone and thus already in a backup.
In theory they also have a file history for iCloud and you could restore files for up to 30 days, I think. I say in theory because the few times I have tried it, it was incredibly unhelpful. But that's pretty much usual with Apple, the practice is actually very far for the theory/marketing.
That's a leap, but I understand your point of course. It _MIGHT_ also be said it all came from ObjectiveC experts having a first go at Swift, too. Or from groups that were run by some common set of "get it out the door" middle management types.
Or any of a thousand reasons.
And of course, Apple has a middle management problem, but that comes with Tim Cook's style; he cares about values that are just not conductive to progress and excellence. It all ends up about "getting shit done" and not caring that much if the results are actually any good. So, they do stuff on schedule and are content with it no matter how bad it is, typical careerist behavior.
To be fair, a lot of our modern society seems to have been overtaken by these types of people, they are very popular and very "successful"; it's more noticeable at Apple because it used to be very different...
(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
https://ss64.com/mac/say.html
> 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...