1. How to Change Where Screenshots Are Saved?
1.5 A zsh Script to Re-Name Your Screenshots
2. How to Prevent macOS From Sleeping?
3. How to Start (open) an App From the macOS Command Line?
3.5 How to open a Network drive
4. How to Schedule an App to Run At a Specified Time?
5. How to Check the Size of a Directory?
6. How to Check Battery Status from the Command Line?
7. How to Send Files to the Trash from the macos Command Line?
8. How to Find the Hardware Architecture and OS Version for My Mac?
9. How to Combine/Concatenate Multiple PDFs?
10. How to Search My Command History in Terminal?
11. How to Disable Auto-Booting When Opening the Macbook Lid?
12. How to Copy command line Output to Pasteboard/Clipboard?
14. How to Show Hidden Files in Finder?
15. How to Recover a Bodged git Repository?
16. How to Restore the "Lost Startup Chime"?
17. Weird Behavior With zsh; noglob and rm -rf
18. How to Hide All Open Windows on a Desktop? ('Show Desktop')
19. How to Set Default Editor for CLI/Terminal App
20. How to See Your Environment Variables
21. Where is the PATH Environment Variable Stored on MacOS?
22. How to Enable cron in macOS
23. Getting Up to Speed on zsh
24. Upgrade Xcode on High Sierra... or Why Does Apple Crap On Us?
25. Cleaning and Restoration of iTerm2
26. "client_loop: send disconnect: Broken pipe"
28. Tools for Isolating Hardware Faults in Macs
30. The Elusive Symbol for Degree°
31. The Strange Case of airport
32. Do You Want to Move That File, or Copy It?
33. Should You Put Siri on an "iLeash", or Put Her Down?
34. Burning ISO files to DVD Using hdiutil
35. Switch the Profile in your current Terminal window
36. Stop Apple's Updates from trashing your customized /etc files
37. Don't fret over loss of youtube-dl
38. Add "QuickLook" visibility for .webp images in older Macs - UPDATED 20240823
40. Refresh shell configuration without restarting
42. Convert .mp4 videos to .webp format using ffmpeg
43. yt-dlp and ffmpeg work together to merge audio and video
44. Using scutil to manage macOS VPN connections
45. Using diskutil to format an external drive as a FAT filesystem
46. Cure this truly annoying mouse or glidepad behavior in iTerm2
47. Change your time zone from the command line
48. How do I open a new Terminal window or tab in a folder from Finder?
49. PageUp and PageDown in Terminal.app (and iTerm)
Two lines of input are needed at the command line; regular user privileges are sufficient. The first changes the default location, the second restarts the SystemUIServer
$ defaults write com.apple.screencapture location ~/Desktop/screenshots
$ killall SystemUIServer
Alternatively, you may specify the full path:
$ defaults write com.apple.screencapture location Home/yourusername/Desktop/screenshots
$ killall SystemUIServer
This will cause all screenshots to be saved in a folder called screenshots on your Desktop. You may, of course, store them anywhere you wish*.
* Note that you must create this folder if it doesn't already exist! ↑toc
Apple does several things I don't particularly like. One of them is the file-naming convention they dictate for screenshots. Somewhere in the abyss of configuration files, there is probably a prescription for that, but finding Apple's documentation is never easy - even if it exists. For example, there is a shell command named screencapture - it even has a system manual at man screencapture! If you read to the bottom, you'll find a couple of interesting items:
-
BUGS - Better documentation is needed for this utility.
-
June 16, 2004
So - someone at Apple recognized their documentation sucks, yet the document was last updated in mid-2004!
But we're not here to belabor the poor state of Apple's documentation. Here's a script that will do a bulk-rename of all the files in your screenshots (or any other) folder:
#!/bin/zsh
# shotfnmv.sh
cd $HOME/TestShots
for afile in *.png
do
echo $afile
oldfile=$(basename "$afile")
echo $oldfile
if [[ $oldfile == *"Screen Shot"* ]]; then
echo "Found an Apple-formatted Screen Shot file."
oldtimestr=$(echo "$oldfile" | awk '{ printf "%s-%s_%s\n", $3, $5, substr($6,1,2) }')
echo $oldtimestr
newtimestr=$(date -j -f %Y-%m-%d-%I.%M.%S_%p "$oldtimestr" "+%Y-%m-%d-%T")
echo $newtimestr
newfile="screenshot-${newtimestr}.png"
echo $newfile
# mv "$oldfile" "$newfile" # overwrite fienames in place
cp -np "$oldfile" "$newfile" # copy file to same dir, new name
# cp -np "$oldfile" ../TestShots2/"$newfile" # copy file to different dir, new name
fi
doneThe shebang calls for zsh, but I believe the script will run in bash, and perhaps other shells. The date and awk utilities are the "native Apple" versions in /bin & /usr/bin. I've tested the script on my MBP macOS 10.15.6, and it seems to work fine for me. Note there are two.#/comments near the end that give you the option to copy or overwrite the original files. Also, the script still contains echo commands inserted for debugging - which can of course be commented out to reduce the noise. While I have tested this, I urge caution because Apple is free to change their file-naming format without notice, and it's not been rigorously tested against a wide variety of filenames. The latest version of the script is available in the ./src folder here.
Beyond that, a few other points worth mention:
- The string
Screen Shotis used as a filter to select only Apple-named screenshots; this will exclude files with, for example,Screen Recordingin the filename - or any files you have saved in the folder with any name that doesn't begin withScreen Shot. awkis used to parse the filename into fields, and extract the original date-time string from the original file name. This original-format date-time string is saved in the shell variableoldtimestrdateis used to re-formatoldtimestrinto a cleaner (IMO) format innewtimestr; i.e. they are the same date & time, but in a different format.- After that it's only a matter of copying (
cp) the new file to retain botholdfile&newfile, or overwriting (mv) theoldfilewithnewfile.
Caffeine may do the trick; specifically caffeinate may be exactly what you need for your Mac. Know first that man caffeinate is your friend; enter it at the command line, and you'll find all the documentation for using this utility. caffeinate creates assertions to alter system sleep behavior. Following are a couple of general use cases:
$ caffeinate -s
or perhaps more effectively as follows:
$ caffeinate -s &
[1] 1558 (IF YOU WISH TO RESTORE THE SLEEP PATTERN AFTER SOME TIME, simply kill it as follows: )
$ kill 1558
Used in this way, caffeinate is a blunt instrument. This command simply creates and holds an assertion that will prevent the Mac from sleepingNote1 as long as it remains on ac/mains power. Run in the background, you can continue the terminal session for as long as needed, and then simply kill caffeinate's PID to release the assertion and restore sleep patterns.
$ caffeinate -w PID
When used with the -w argument, sleep will be inhibited as long as the process ID PID is active. Once the the process exits, the assertion is released, and the configured sleep behavior will resume when appropriate.
Note also that Process ID's are available from Activity Monitor, or can be listed in the terminal by entering ps -Al
Note1: Know that caffeinate will not prevent a scheduled automatic logout.
There may be occasions when you want or need to start an application from the command line. Or perhaps start an app from a script, or even to start the app at a specified time (more on scheduling in the sequel), or on an interrupt-driven basis triggered by an event. The open utility (ref. man open) is designed for this. For example, you want to start Chrome to check your Gmail account - how would you do this? Here's one way:
a. get the location of the app
$ ls -d -1 /Applications/*.* | grep Chrome
/Applications/Google Chrome.app
b. get the URL for your Gmail inbox:
https://mail.google.com/mail/u/0/#inbox
c. use open to start Chrome and load GMail:
$ open -a "/Applications/Google Chrome.app" https://mail.google.com/mail/u/0/#inbox
*Note that the file specification must be inside quotes to "protect" the space in the app name.*
d. open also has some options specific to text editing; for example to open a man page with your system's default text editor. Here, we'll open the man page for open in the default text editor :
$ man open | col -b | open -tf
Which can be quite useful for perusing the system documentation offline (in this example, the man page for open), and/or making additions or changes to it either for your own use, or to share.
open can also launch Finder, and open a network share:
a. Open Finder, click the Go item in the Menu, and then Connect to server... (or ,⌘K)
b. Enter smb://server/share, and click the Connect button, OR click Browse to select a server & share.
c. A new Finder window/tab will open showing the contents ofsmb://server/share. That connection is now registered in the LaunchServices database, and entering open smb://server/share in Terminal.appwill open to that share in Finder.
Note: This will also work for any other supported network file system: cifs, nfs, etc.
In current versions of mac os, there are (at least) three distinct approaches to scheduling:
-
cronis the standard (as in long-standing) method for scheduling. It's been around since the early days of Unix. Thatcronremains as a viable, well-maintained app today is a testament to its utility. And as a derivative of the BSD flavor of Unix, it is fitting that it remains a component of mac os. However, we must note that Apple has not maintained thecronsoftware they distribute with mac os;man cronreveals that the current version oscronin mac os ver 10.14.6 (Mojave) is vintage June 17, 2007. See the example below. -
launchdis a much more complicated creature thancron, but it's got an Apple pedigree. It was developed by Dave Zarzycki, an Apple employee who started with them in 1996 as a 17 year-old, self-taught programmer.launchdcan do more thancron, but it's much more difficult (even arcane) in use. Consequently, we'll covercronhere, and pick uplaunchdin this installment. -
atis a bit of an outlier in the sense it's less frequently used. As of macOS Catalina,atis still included, and supported (in the fashion that Apple supports such things). If you're interested, read two things:man atand this Q&A on Stack Exchange: Making “at” work on macOS that explains how to work around the debris known as Apple's "open source" environment. N.B. that Apple's version ofatisn't as up-to-date as the one in your favorite Linux distro, but it does work as shown in the following example:atExample:% at now + 1 minute <enter this sh command:> echo "Hello World from at" <enter ^D> job 9 at Wed Oct 7 03:17:00 2020 % at -l 9 Wed Oct 6 13:17:00 2020 %
So... now what? Where's the output? Does this
atthing work at all? Yes, it created the requested output... it's in an email message! You can verify this by checking your email with the
mailcommand. Alternatively, you may use aredirectto send the output to a file; e.g.echo "Hello World from at" > ~/at_output.txtcronExample:Let's assume, you want to check your Gmail account each day at 12:00. How would you do this? Here's one way to do this using
openandcron:cronevents are declared and scheduled in thecrontab. They follow a specific syntax, although there are variations across the different versions ofcron. We're working of course with Mac OS, and that means the Vixie (named after Paul VIxie) version ofcron. Creating an entry in yourcrontabfile is done with a simple command:crontab -e
If this is the first time you've edited your
crontab, you'll probably find the editor opens a completely blank file. Many Linux systems will have a defaultcrontabthat has comments and helpful hints, but Mac OS does not.Let's schedule our event now. Enter the following line in the
nanoeditor you've just opened:00 12 * * * open -a "/Applications/Google Chrome.app" https://mail.google.com/mail/u/0/#inboxNext, tell
nanoto write your newcrontabby enteringctrl-o,enterto accept the filename, andctrl-xto exitnano. And that's it. You've just scheduled Chrome to start and fetch your Gmail inbox every day at 12:00 noon.You'll recognize the
opencommand and the parameters that follow it in thecrontabentry. We've prepended a strange-looking sequence to that:00 12 * * *This is simply the schedule information. It tells
cronwhen to execute the command that follows. If you want to re-schedule for a time other that 12:00 noon, all you need change is the time.man crontabwill guide you in the options for specifying the time and date. Until you become familiar with the syntax, you should use the crontab guru to check your schedule. You'll learn thatcron's simple syntax is quite flexible.
You can of course do this from the Finder menu: File, Get Info, but it may be quicker from the command line.
For a directory on your Mac's HDD:
$ du -sh /path/to/directory
For a network drive that's mounted:
$ du -sh /Volumes/sharename/path/to/directory
The pmset utility provides a host of information, and allows manipulation of power management settings from the command line. For example, to get battery status:
$ pmset -g batt # and for example, my Mac now reports"
Now drawing from 'AC Power'
-InternalBattery-0 (id=1234567) 100%; charged; 0:00 remaining present: trueThe -g (get) option provides data on current settings and logfiles. It can be run with normal user privileges. pmsetcan also change settings (e.g. standby, sleep, spin-down of disks, display, etc.), but those require root/su privileges. Documentation is available from man pmset.
This is easily and elegntly done thanks to the work of dabrahams. The latest version of the command line utility named trash is available in this gist on GitHub, and now here in this repo. Its creation was spawned by a Q&A on Stack Exchange, and initially posted in this answer. There is always rm of course, but it's a permanent and irrecoverable deletion. What makes trash special is that it moves files to the Trash folder, essentially replicating the system's Move to Trash feature available in Finder. And from Trash of course you have the option to recover the file, or delete it permanently.
It's written in Python, and open source. If you want to "integrate" trash into your system:
-
Save the script as a file named
trash, and copytrashto/usr/local/bin -
$ chmod a+rx /usr/local/bin/trash
Because macos has (some of) its roots in BSD Unix rather than Linux, the machine command will reveal hardware:
$ machine
x86_64h # on a new-ish machineAnd if you want to see perhaps the shortest man page in the entire world, check out man machine. :)
However, the following Linux-style command also works:
$ uname -m
x86_64uname has several other options, all described in man uname.
And finally, suggest that you do not use this:
$ arch
i386This is of course an incorrect answer for 64-bit processors, but one that you will get as of today (Mojave 10.14.4)! Some have suggested that the i386 output simply means that it's capable of running 32-bit programs. However, man arch makes no such statement. Consequently, it's my opinion that Apple has simply dropped the ball! In any case, the information is virtually useless.
To get the version of the OS:
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.4
BuildVersion: 18E226Note however, there is more confusion/inconsistency between the sw_vers command, and uname -r[sv]: both commands claim to display the OS version, but uname -r[sv] actually gives the version of its kernel (currently named Darwin):
$ uname -v
Darwin Kernel Version 18.5.0: Mon Mar 11 20:40:32 PDT 2019; root:xnu-4903.251.3~3/RELEASE_X86_64This information is also available from Apple's unique-to-the-Mac command line utility system_profiler SPSoftwareDataType. Its output shows System Version, which corresponds to OS version given by sw_vers, and Kernel Version which corresponds to OS version given by uname -r[sv]. And yes, you're correct… this is a bit of a mess!
$ system_profiler SPSoftwareDataType
Software:
System Software Overview:
System Version: macOS 10.14.4 (18E226)
Kernel Version: Darwin 18.5.0
Boot Volume: Macintosh HD
Boot Mode: Normal
Apple has this one covered, and it's easy if you know the trick. You should also know that the Quick Actions > Create PDF option in Finder may not show up! When you move the pointer over Quick Actions in Finder you may see only the option Customize.... If that's the case, click Customize..., then tick the box next to Create PDF. This will add Create PDF as an option for Quick Actions.
Here are some useful techniques:
-
Type control+r at the command prompt. This brings up a search prompt:
(reverse-i-search):. Type whatever you can recall of a previously used command (e.g.etc). As you type each character, the search continues. You can iterate back through all of the search results with control+r. When you've found the command you were looking for, hit theenterkey to run it again "as-is", or make edits to the command (use either of the left-right arrow keys) before you run it. If you want to stop searching without running a command, type control+g. -
You can use the
historycommand!historyoutputs the entire history tostdout. As such, you can filter the history by piping it to (e.g.)grep:history | grep etc, or redirect it to a file (e.g.history > mycmdhistory.txt), or any other command (e.g.history | tail -5). -
Of course, you can still use the up-and-down arrow keys to step forward (or backward) through the command history, but if your command history is extensive, this will take time.
This useful bit of wisdom was found in this article in OSXDaily. You can manipulate the MacOS firmware from the command line:
sudo nvram AutoBoot=%00Note that you must execute a clean shutdown to save this value. To restore the AutoBoot feature:
sudo nvram AutoBoot=%03--OR--
Restore ALL NVRAM settings by rebooting the MacBook while holding down the Command+Option+P+R keys (yes, this is a two-handed operation :)
What other NVRAM settings are available for changing?
nvram -pwill list available options... but it's very messy!
You can copy from stdout and paste to stdin using one of the several clipboards available.
$ ls -la | pbcopyYou can then paste this output into a document using the command-v keyboard shortcut.
Similarly, using pbpaste you can paste text you've copied to a file; e.g.
$ pbpaste > newfile.txtSee man pbcopy for further details.
14. How to Show Hidden Files in Finder?
There are many hidden files and folders in MacOS. We have to guess what Apple's motivations are for designating certain files and folders as hidden, but it seems likely this default configuration is to protect users from themselves. However, there are numerous situations where it's very useful to be able to see files in Finder that are hidden from our view bt default. Examples abound:
- all the files and folders associated with MacOS' Unix underpinnings; e.g.
/usr/local/bin,etc, and many more. - if you maintain a
gitrepository on your Mac, there will be files that you will need to edit; e.g..gitignore. - all
mounted drives and shares are listed under/Volumes, and it is occasionally useful to see inside this hidden folder.
Fortunately, there at least two simple ways to turn visibility of hidden files and folders ON and OFF.
The quickest and simplest method is to use the keyboard shortcut when a Finder window is in focus:
⌘shift.
You may also use the CLI as follows to render the hidden files as visible from within Finder:
$ defaults write com.apple.finder AppleShowAllFiles TRUE If you have open Finder windows, you may need to close them all with this command before you see the effects of this change; i.e. before Finder shows the hidden files in its listing:
$ killall FinderOpening a new Finder window will reveal the hidden files and folders. To return to the default:
$ defaults write com.apple.finder AppleShowAllFiles FALSE && killall FinderRecently, I inadvertently deleted all of my local GitHub repositories. In a comical sequence of poor decisions I made things worse by copying the entire repo from a backup, but it was not in sync with the repos on GitHub. Further attempts to resolve the issues only made things worse. Then it dawned on me that this what git was made for! A quick bit of research provided the answer - from the CLI:
$ git fetch origin
# some output ...
$ git reset --hard origin/masterA few things to review beforehand! :
- execute these commands from the local directory where you want your repo to live,
- The
remoterepository is the origin you want (in my case, the remote repo at GitHub was myorigin) - The
branchyou want to restore is themasterbranch - ↑
The long lost startup chime has been found by this fellow. Here's how to get it back on your Mac:
sudo nvram StartupMute=%00
sudo reboot # alternatively, `Restart...` fm the System menu
# Hear the Lost Chime once again!
# When you get tired of it:
sudo nvram StartupMute=%01More details and Chime Trivia can be found here.
And if you're into mac nostalgia you can get all the default macOS wallpapers in 5K!
As most of you will be aware, Apple has made the decision to change the default shell from bash to zsh in macOS Catalina. There's more to come here on zsh, but for now I'll include some discoveries I've made here.
-
zsh'over-globs'!This queerness took an hour from my life:
% curl -o rpiforum.html -L https://www.raspberrypi.org/forums/viewtopic.php?p=1528736 zsh: no matches found: https://www.raspberrypi.org/forums/viewtopic.php?p=1528736 # wtf??
A very old problem according to this resource. Two relatively simple solutions that might never occur to you are:
% curl -o rpiforum.html -L "https://www.raspberrypi.org/forums/viewtopic.php?p=1528736" % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 120k 0 120k 0 0 199k 0 --:--:-- --:--:-- --:--:-- 199k # OR, A MORE PERMANENT PATCH: % alias curl='noglob curl' % curl -o rpiforum.html -L https://www.raspberrypi.org/forums/viewtopic.php?p=1528736 % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 120k 0 120k 0 0 204k 0 --:--:-- --:--:-- --:--:-- 204k
-
zshwants to have a "conversation" about usingrm -rf!Irritatingly,
zshrefuses to follow orders when the order isrm -rf; it insists you confirm that you really want torm -rf ./somefolder/*. In weird 'Microsoftian' logic, you eventually learn that this is not a bug - it's a feature. How do you disable this feature?Add the following line to
~/.zshrc:setopt rmstarsilent
fnF11 - this will toggle Show & Hide all app windows on a desktop.
If you run a command that invokes a text editor (e.g. crontab -e), you may find yourself in the vi editor. vi is fine once you're used to it, but proficiency in viwill require time and effort. If you'd prefer to avoid learning vi, you can easily set your default to a more user-friendly editor like nano:
export EDITOR=nanoEnter this at the command line in Terminal.app. From this point forward, anytime you run crontab -e, your crontab will open in nano instead of vi. If you want to try vi later, simply export EDITOR=vi.
Alternatively, you can modify your zsh or bash configuration file(s) from the CLI:
zsh:
echo 'export EDITOR=nano' >> ~/.zshrc
echo 'export VISUAL="$EDITOR"' >> ~/.zshrcbash:
echo 'export EDITOR=nano' >> ~/.bash_profile
echo 'export VISUAL="$EDITOR"' >> ~/.bash_profileAfterwards, you can source the config file for it to take effect immediately in all open terminal windows:
zsh:
source ~/.zshrc
# - or -
. ~/.zshrc # the POSIX-compliant option!bash:
source ~/.bash_profile
# - or -
. ~/.bash_profile # the POSIX-compliant option!From the command prompt:
% printenv
# or if you prefer not to clutter your terminal history:
% printenv | lessThe files containing the system's default PATH environment are in two places:
/etc/paths- Other folders are added (typically by 3rd-party application installers) in on of the files under
/etc/paths.d - Typically, your PATH environment variable is further modified for your individual use in:
~/.zprofile- if you usezsh, or~/.bash_profileforbashusers
Beginning with Catalina, Apple has "enhanced security" by disallowing operations that have long been allowed. cronis one of those. Restoring cron's privileges requires it be granted Full Disk Access in System Preferences/Settings. Doing this using the GUI is a brief process:
Open System Preferences/Settings app & navigate to the Privacy tab in Security & Privacy (or to Full Disk Access under Privacy & Security)
- Select the
Full Disk Accessitem in the listing (orPrivacyin the tab); this reveals a list of apps. - Click the
+symbol at the bottom of the list; this will yield aFinderwindow. - With the
Finderwindow in focus, enter command+shift+G, and then enter/usr/sbinin the dialog box. - From the
/usr/sbinlisting inFinder, select thecronapp; it should now be added to theFull Disk Accesslist; ensurecronis checked/enabled.
You may now proceed to populate your crontab with jobs, although in the later versions of macOS (e.g. Ventura) you won't find a helpful default crontab to help you get started.
↑
Apple has decided that the most-commonly-used shell (bash) should no longer be the default shell for macOS, so in Catalina they have made zsh the default. The motivation for this decision is, uh... interesting, I think - if this is true. Personally, I find bash more comfortable, but that's just my opinion. You should make up your own mind, and here's a reading shortlist to help with zsh:
- From How-To Geek: What is ZSH, and Why Should You Use It Instead of Bash?
- From Armin Briegel at Scripting OS X, a series of articles: Moving to zsh, also available as a book.
- From linux today, a blog post on Writing scripts for
zsh. - And if you want, here's how to restore
bashas the default shell on Catalina - an entire article on this:
chsh -s /bin/bashFinally, know that if you prefer bash, you're not stuck with Apple's "antique" version of bash; you can get the latest release through MacPorts.
Apple's abject failure to maintain many of their "Open Source" tools has led me to install MacPorts. My ancient MacBook Pro Late 2011 runs High Sierra, and I've been reasonably happy with it - it's a lesser hassle than my new 2019 MacBook Pro w/ Catalina. Also, since this vintage Mac has a removable SSD, I can easily back out of any failures. Anyway... as I learned, before installing MacPorts I had to upgrade XCode. XCode was installed from the AppStore, so I figured it would be an easy upgrade. But in yet another demonstration of how much Apple cares for their customers, this was far from easy. And no - I don't want to hear any lame explanations for this from Apple's supplicants - just STFU, please.
That said, I followed a recipe I found here REF @cerniuk's post for uninstalling Xcode, and it seems to work. I'm sharing it here w/ one minor addition in hope that it'll help someone else: Here's what I did:
Remove the following:
- /Applications/Xcode.app
- ~/Library/Caches/com.apple.dt.Xcode
- ~/Library/Developer
- ~/Library/MobileDevice
- ~/Library/Preferences/com.apple.dt.Xcode.plist
- ~/Library/Preferences/com.apple.dt.xcodebuild.plist
- /Library/Preferences/com.apple.dt.Xcode.plist
- /System/Library/Receipts/com.apple.pkg.XcodeExtensionSupport.bom
- /System/Library/Receipts/com.apple.pkg.XcodeExtensionSupport.plist
- /System/Library/Receipts/com.apple.pkg.XcodeSystemResources.bom
- /System/Library/Receipts/com.apple.pkg.XcodeSystemResources.plist
Installing an older version of XCode is a bit different - you can't get it from the AppStore. Fortunately, MacPorts keeps a list of downloads, and a decent set of instructions. Once that task is accomplished, you have an upgraded XCode install that supports MacPorts (at least until Apple decides to break things again).
Oh, one other thing... checking your version of XCode Tools is reasonably straightforward, but try to find the version of XCode Command Line Tools. Yeah... frustrating, isn't it?
iTerm2 is a popular terminal emulator for macOS. Some prefer it to Apple's native Terminal.app. I use it for some things, but find its many features can be distracting at times. I realized recently that I had wandered off in the weeds wrt my Preferences...Profiles settings, and that Default settings were long gone & far away from the original settings (which weren't that bad). For all the knob dickers, here's the cure from the iTerm FAQ:
% defaults delete com.googlecode.iterm2Know this: This clears ALL settings in iTerm2. If you want to create a restore point for your iTerm2 settings, you may find some help in this Q&A on Stack Overflow - be sure to read all the comments!
Related to this is iTerm2's Dynamic Profiles which are saved in one or more plist files formatted as JSON or XML (or in binary). Profile changes are made immediately (thus, dynamic).
Irritating, no? If your SSH connections are dropping like flies, you can stop reduce that by running your SSH connections under the native caffeinate command:
% caffeinate -i ssh user@hostThis should maintain an SSH connection for as long as you need it IF you are "plugged in" to the charger. It requires no additional software, and will maintain other network connections and long-running processes even when the lid is closed on a MacBook. You can read more details on this neighboring page.
Lest I be accused of ignoring the occasional and potentially useful item that Apple publishes, here's one that might come in handy in a disaster recovery context: Creating a Bootable Installer for macOS.
For hardware built prior to June, 2013, use the Apple Hardware Test
For hardware built after June, 2013, use Apple Diagnostics.
macOS has a large set of symbols (⌘, ⌃, ␠, ↑ + hundreds more) that can be inserted into most documents you create (or edit). Use your keyboard commandcontrolspace (or, ⌘, ⌃, ␠) to see the entire pallet of symbols. Click on the one you wish to use, et c'est voilà.
Several ways to do this:
- For the GUI people: controlcommandspace (as above!)
- Keyboard version (tiny): optionk (note: actually the diacritical mark)
- Keyboard version (normal): shiftoption8
I've seen references to "Airport" in various articles for years without knowing what they were on about. Yeah - there's the odd app called AirPort Utility in the folder labeled Other in Launchpad- the folder where they put a few other seldom-used apps. But as far as I knew, this AirPort Utility was used only for light administrative duty on my old-and-now-no-longer-manufactured Time Capsule. I was amazed to see that it was still included in Catalina - Apple being so fond of casting out legacy items.
But as it turns out, there's a command-line utility named airport that's been around for quite some time - maybe since Apple first embraced wifi? It may be useful for exercising a bit of administrative control over wifi, but I'll postpone that discussion. This note is simply an introduction.
The strange things about airport are its location in the filesystem, and the stupefying lack of documentation. Even by Apple's low standards for documentation, man airport is laughable! If you never use airport, you should at least enter man airport from the command line - what were these wankers thinking?! Equally laughable is the output of airport -h - the so-called "help menu"!
As for its location: /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport
Yes - seriously - that's where it is - at least for Catalina & Mojave. Older versions of macOS have it in a different, but equally odd location. If you want to try airport you could start by reading this post on OSX Daily. I hope to find a use for airport in conjunction with networksetup to overcome the promising-but-utterly-useless Network configuration tool in the System Preferences app - but that's for another day.
If you ever use Finder, this is for you. As you have likely noticed, there is an unspoken rule behind Finder's behavior during drag-and-drop operations on files:
On the same volume: move is default. On a different volume, copy is default.
But these default behaviors are not what we want in some situations. Here's how to modify that:
Command key while dragging changes copy to move.
Option key while dragging changes move to copy.
If you find it tedious to remember this, one option is to use mv or cp from the CLI.
With the "Siri Privacy Scandal" out in the open now, you may have wondered what, if anything, you should do about it. I know I have. After understanding what happened, it feels like Apple simply cannot be trusted. For me - the fact that they didn't take ownership of the issue was the biggest disappointment - a punk-ass move IMHO. I should just accept the fact that giant corporations are inherently untrustworthy, and run by people who might throw their Mother overboard to improve their odds... I should grow up, and accept this. Anyway - now the time has come to decide what to do about it. Here are some of the options I've considered:
- Leave it disabled - as it has always been on my new Macbook
- Remove Siri from the TouchBar - definitely!
- Rip it out - remove the executable/app file(s)
On Catalina and Mojave, there's a control panel for Siri in System Preferences. The Enable Siri option can be checked - or un-checked. It ought to be that simple - but it's not. Since Catalina 10.15.1, Apple added "new features" to the Siri control panel - giving you "more control" over your personal data. Hmm - Apple's post-Siri-Scandal pledges and promises are already being watered down? In all honesty, I don't know. But given that Apple's software is closed-source, and their record is not great I wouldn't take any wagers. Note to Apple: Lost trust is hard to recover.
Removing Siri from the "Touch Bar" (Mojave-speak), or the "Control Strip" (Catalina-speak) likewise has been made harder than it should be. The link in option 2. above is a SE Q&A that illustrates this point. If that doesn't work for you, my best suggestion is to search for your particular OS.
Option 3 seems the ultimate solution to me. But there's a question of how to do this. Search as much as you wish, but you won't find a how-to guide for removing Siri published by Apple. Maybe there's a reason for that - maybe some Siri software components are needed in critical system functions. I don't like the fact that Apple says nothing at all about this, 'cause I know the question has been asked. The only guidance I found for removing Siri was in this article. But the the author's solution comes down to sudo rm -rf on the system library folder where Siri lives. Except for a restore from backup, this approach is 100% commitment!
Rather old-school, but DVDs still come in handy on occasion. For example, if you've been called upon to repair a relative's Linux PC, and don't have a USB drive to spare. Fortunately, you do have one of Apple's "Super Drives" from back in the day, and a big stack of DVDs you got on sale 10 years ago :)
You might think you can use Balena Etcher for this (as you do with USB drives), but you will be disappointed to find that the bunch at Balena doesn't support that - despite the fact there was a lot of discussion on the subject some time ago!
Fortunately, in a rare case of Apple's software does occasionally do something useful, the command-line utility hdiutil rises to the challenge. A well-written CLI utility is a thing of beauty, and this is not only beautiful, but it far exceeded my expectations. I should mention that this was done on my Catalina system, so YMMV. But here's how it looked on my system:
seamus@Dung-Pro ~ % cd Downloads
seamus@Dung-Pro Downloads % hdiutil burn ubuntu-22.04-desktop-amd64.iso
Preparing data for burn
Opening session
Opening track
Writing track
.......................................................................................................................................
Closing track
.......................................................................................................................................
Closing session
.......................................................................................................................................
Finishing burn
Verifying burn…
Verifying
.......................................................................................................................................
Burn completed successfully
.......................................................................................................................................
hdiutil: burn: completedAwesome! The physical configuration ICYI:
Yes - you can do this, and it comes in really handy sometimes:
1. Right-click an open space in the Terminal window, or <kbd>command</kbd><kbd>I</kbd>
2. Choose `Show Inspector` from the menu
3. Click on the `Profile` tab in the `Inspector` window
4. Choose a new profile for the current window
It's quite irritating to spend time carefully tailoring files in /etc, only to see them reverted to their original contents by Apple's F** Updates. It's even more irritating that Apple does this without notification, explanation or documentation. You learn of it only after an Update when all your shit breaks! Here's a solution that seems to work; it preserved my /etc/auto_master file during a recent Ventura Update to 13.6. It should work for other files in /etc also - perhaps even in other locations:
sudo chflags simmutable /etc/auto_master
# REF: 'man chflags'; use 'nosimmutable' to undo when edits are requiredIf you're a user of youtube-dl, you may have seen this announcement announcing that Germany's court system has apparently pulled the plug on this popular app. But don't fret, the folks at MacPorts have brought you a replacement in the form of yt-dlp. They also have their own website/repo here on GitHub. The king is dead; long live the king.
[UPDATED 20240823]
My macOS Mojave is still a good machine - I use it regularly. I've not upgraded it because I feel that Apple "fucks you over" on the upgrades - but that's only my registered opinion :) What's not opinion is that Apple does not support their older machines for more that a couple of years. Using an older Mac, there are a few upgrades that I might be missing out on. But I've found that MacPorts usually takes care of the important stuff.
However, I couldn't find a solution for the "preview/QuickLook" functionality for the (now) ubiquitous .webp graphics. Searching online was revealing... why do some assholes try to take over other people's work? Yes - that's correct... the assholes at laptopmag.com tried to take credit for 'emin's open source project'. They gave emin (the original author of WebpQuickLook) no credit when I looked.
Anyway: The solution is available from emin's GitHub site, and it's still up as of this writing (10 Aug 2024).
If you're having problems with emin's webpQuickLook, that might be because it hasn't been updated in a while. There's a more up-to-date fork of webpQuickLook available from lincerely's GitHub page. He's updated several things, including the installation script. I just installed IAW the instructions. It seems to be an improvement, but it's not flawless! A few things I've noticed:
- It's not "Quick" in all cases; in some cases I'd call it "Semi-Quick" :)
- Sometimes, it doesn't seem to work at all! I've had some luck in restoring it by re-running
qlmanage -rfrom the Terminal. - It completely fails on some
webpimages. In all cases that I've tested, the failingwebpimages turned out to be animations when I viewed them in 'Chrome'.
So - I've got this old-ish Macbook - a 2016 model. In my fashion, it was bought new with Mojave installed, and it still has Mojave installed. Why don't I upgrade? Because back when I did perform Apple's recommended upgrades was inevitably a recipe for pain and frustration. No upgrades for me; I don't care how many of those little red dots Apple puts on my 'System Preferences' shortcut icon.
Working with an older machine is sometimes a blessing. For one thing, you have it long enough to see some of the abject stupidity that's baked into the product. The supidity I'm picking on today is Apple's implementation of whereis. Unlike in Linux - where the differences between which and whereis are clear and mildly useful, Apple forgot the differences in their infelicitous quest for "security". Here's what I find so incredibly stupid about Apple's whereis command: by default whereis searches only the PATH defined in a string called user.cs_path. And it gets better: the user.cs_path string is apparently baked into Apple's firmware (somewhere it is un-reachable in any case); far beyond the reach of the sysctl utility. What's that you say... "What do you mean beyond the reach of sysctl?" What I mean is that the sysctl utility provided by Apple has had the -w (--write) option removed; to quote Apple's man sysctl:
The −w option has been deprecated and is silently ignored.
I thought this could be overcome somehow by disabling SIP, but I tried that without success.
You may wish to ponder this for just a moment: Apple has relegated whereis to searching only in this PATH: /usr/bin:/bin:/usr/sbin:/sbin. And unlike the Linux version of whereis, some versions of Apple's whereis are totally silent on the location of any documentation (e.g. Mojave). AFAICT, Apple's whereis informs you only where Apple keeps their 20+ year-old tools! And this is why I've made the following change on my "Mojave" system:
cd /usr/bin
sudo mv whereis whereis.sucks
sudo ln -s /usr/bin/which whereisThere are two user-owned files that control many aspects of the shell's behavior - uh, interactive shells, that is: ~/.profile & ~/.bashrc. Likewise for zsh, the ~/.zprofile & ~/.zshrc. There will be occasions when changes to these files will need to be made in the current session - without exiting one shell session, and starting a new one. Examples of such changes are changes to the PATH, or addition of an alias. Here's how to refresh/reload your shell configuration:__
$ source ~/.profile # use this for bash
$ source ~/.bashrc # "
% source ~/.zprofile # use this for zsh
% source ~/.zshrc # "
# OR ALTERNATIVELY:
$ . ~/.profile # use for bash + see Notes below
$ . ~/.bashrc # "
% . ~/.zprofile # use for zsh + see Notes below
% . ~/.zshrc # "Note 1: The dot operator;
.is a synonym forsource. Also, it's POSIX-compliant (sourceis not).
Note 2: Additions and removals from
~/.bashrcbehave differently: If something is removed from~/.bashrc, this change will not take effect after sourcing~/.bashrc(i.e.. ~/.bashrc); you must re-start your shell (e.g.exec bash, orexec zsh).Example: Add a function to
~/.bashrc:function externalip () { curl http://ipecho.net/plain; echo; }. Now source it with. ~/.profile. You should see that the function now works in this session. Now remove the function, and then source it again. The function is still available! Only restarting (log out & in), or starting a new shell session viaexec bash/exec zshwill remove it.
A few people have asked me why I don't ever upgrade a Mac. It's a fair question, and deserves a fair answer.
My SOP is based on personal experience that began years ago, and continues today. I found that after upgrading, occasionally very weird things happened - things that on a couple of occasions turned into weird AND horrible experiences that trashed personal data, or made it impossible to do things I'd made a habit of doing. I develop methods for doing things, and I cannot tolerate a third party that arbitrarily changes things in "their OS" - without notification or warning. First and foremost: I do not trust Apple. In fact, I think they suck - big time. This may have something to do with their enormous size... I don't really know or care. I hope that addresses the why question.
If you disagree with my opinion, I think that's fine. You may be the sort of person who prefers to weigh up the evidence, and make their own decisions. If that's the case, my hat is off to you. I feel the world would be a better place if more people thought (and acted) independently! And so without trying to influence anyone else's thinking or opinions, I will offer some anecdotal evidence that one might consider in forming his or her own opinion.
Support for .webp is a fairly new feature for ffmpeg, and only became available in MacPorts on 8 Oct 2024.
Here's a recipe I used to convert an .mp4 to .webp (credit to Matt Joseph):
% ffmpeg -i "JW.mp4" \
-vf "fps=10,scale=720:-1:flags=lanczos" \
-vcodec libwebp -lossless 0 -compression_level 6 \
-q:v 50 -loop 0 \
-preset picture -an -vsync 0 JW-convertedmp4.webp For the skeptics (like me), know that .webp may have certain security and performance issues - as discussed in the Wikipedia article. There is some ffmpeg documentation on options for the libwebp codec; other documentation can be found at:
I wanted to download an old movie I found on YouTube: "As Young as You Feel". It seems the only download options were video only or audio only. After a brief search, and perusing the README file in the yt-dlp GitHub repo, I could find no advice or options for how to get "the best" combination of video and audio tracks in a single file.
yt-dlp was installed using 'MacPorts', and I did install it with the [+]ffmpeg variant...??? Perhaps this depends on YouTube? The yt-dlp README file did offer this one thing, but it did not download the highest quality:
$ yt-dlp -f bestvideo+bestaudio/best 'https://www.youtube.com/watch?v=duE8686w78E'
...
[download] Destination: As Young as You Feel (1951) full movie | Marilyn Monroe, Monty Woolley, Thelma Ritter [duE8686w78E].f399.mp4
[download] 100% of 417.31MiB in 00:00:42 at 9.80MiB/s
[download] Destination: As Young as You Feel (1951) full movie | Marilyn Monroe, Monty Woolley, Thelma Ritter [duE8686w78E].f251.webm
[download] 100% of 53.95MiB in 00:00:02 at 24.62MiB/s
[Merger] Merging formats into "As Young as You Feel (1951) full movie | Marilyn Monroe, Monty Woolley, Thelma Ritter [duE8686w78E].webm"
...
$In the end, here's what worked for me 1:
$ yt-dlp -F 'https://www.youtube.com/watch?v=duE8686w78E'
...
251-drc webm audio only 2 │ 53.39MiB 97k https │ audio only opus 97k 48k [en] medium, DRC, webm_dash
140 m4a audio only 2 │ 71.14MiB 129k https │ audio only mp4a.40.2 129k 44k [en] medium, m4a_dash
...
270 mp4 1440x1080 24 │ ~ 2.23GiB 4150k m3u8 │ avc1.640028 4150k video only
137 mp4 1440x1080 24 │ 964.84MiB 1756k https │ avc1.640028 1756k video only 1080p, mp4_dash
...
$ yt-dlp -f 270 'https://www.youtube.com/watch?v=duE8686w78E'
...
[download] Destination: As Young as You Feel (1951) full movie | Marilyn Monroe, Monty Woolley, Thelma Ritter [duE8686w78E].mp4
...
$ yt-dlp -f 140 'https://www.youtube.com/watch?v=duE8686w78E'
...
[download] Destination: As Young as You Feel (1951) full movie | Marilyn Monroe, Monty Woolley, Thelma Ritter [duE8686w78E].m4a
...
$ mv 'As Young as You Feel (1951) full movie | Marilyn Monroe, Monty Woolley, Thelma Ritter [duE8686w78E].mp4' 'AsYoungAsYouFeel.mp4'
$ mv 'As Young as You Feel (1951) full movie | Marilyn Monroe, Monty Woolley, Thelma Ritter [duE8686w78E].m4a' 'ayayf.m4a'
$ ffmpeg -i AsYoungAsYouFeel.mp4 -i ayayf.m4a -c:v copy -c:a aac AYAYF.mp4
...
$ According to man scutil, scutil's raison d'être is to: "Manage system configuration parameters". Wow... that's a large remit! But fear not, this note covers only scutil --nc; i.e. those commands for monitoring and interacting with VPN connections. The "manual" for the --nc subset is obtained by entering the following in Terminal.app:
% scutil --nc helpThis is a rather obscure corner of the world, but useful if you need to automate some aspect of your VPN connections.
VPNs are rather odd things; they act as an "encrypted tunnel" between your Mac's WiFi/Ethernet port to the VPN "server". This server is (typically) not the final destination of your route, but it's where the encrypted tunnel ends. From the end of the tunnel, you can go virtually anyplace you like. In effect, your connection is seen by the destination host as originating at the VPN server instead of your true physical origin. This can be useful for a number of reasons, but rather than trying to cover that here, I'll refer you to this article.
There's something else you should know before reading any further: scutil --nc is useful only in the context of dealing with VPNs that are (have already been) set up/configured using the System Settings, VPN dialog; or, at least, that's all that I'll cover here.
The examples here are based on a set of IPsec VPNs generated using the Add VPN Configuration dialog for Cisco IPSec type VPNs found at the bottom of the System Settings, VPN panel. I generated a few to support this recipe. We'll look at how scutil - illustrated here in a bash or zsh script - can help us use these VPNs.
First - I find it useful to store my VPN configurations in a file. Let's list our VPNs & write them to a file:
$ scutil --nc list | tee vpn.txt
* (Disconnected) 1C5CADA0-EB7B-4A94-A418-59B846D8EB06 IPSec "osl-c03.ipvanish.com-VPN" [IPSec]
* (Disconnected) 8706B438-B924-4FBF-BB85-293BEA17EF17 IPSec "IPVanish-bhx-c18-VPN" [IPSec]
* (Disconnected) 65CD8640-3EA9-4633-ADD8-F8C3DBA40FCB IPSec "hel-c13.ipvanish.com-VPN" [IPSec]
* (Disconnected) 6B205099-5EF0-456C-B8EB-E227DFC07A1C IPSec "iad-b47.ipvanish-VPN" [IPSec]
* (Disconnected) 906D079A-088E-4A2D-8B63-8F4B5523C407 IPSec "ams-a39.ipvanish.com-VPN" [IPSec]
We see that there are two (2) unique fields in each VPN record: the 32-char UUID, and the quoted Display name which was simply our entry in the Display name field when we defined this VPN in the System Settings, VPN panel. We may use either of these to specify our desired connection to scutil.
Next, from the CLI let's first connect (scutil --nc start) to one of our VPNs using the UUID value. After you've seen it work, you may disconnect (scutil --nc stop) as shown below :
$ scutil --nc start "906D079A-088E-4A2D-8B63-8F4B5523C407"
$ echo $?
0
$ scutil --nc stop "906D079A-088E-4A2D-8B63-8F4B5523C407"
$ If the connection is successful, note that the VPN icon in the Menu Bar suddenly comes to life, displaying the length of time the connection has been active. You could also test for the return code from scutil ($?) as shown above.
scutil's -r option is generally a useful precursor to the --nc start option. -r reports the availability ("reachability") of a VPN server. IOW, we check availability of the VPN server using scutil -r, before attempting to start the connection with scutil --nc start.
The following bash script segment illustrates how a VPN connection might be set up with scutil. In this case, the file vpn.txt is first shuffled to put it in random order, and then read sequentially until a successful VPN connection is made:
#!/opt/local/bin/bash
# NOTE: above shebang reflects installation of a current version of GNU bash via MacPorts
VPN_FILE=./vpn.txt
tmp_vpnfile=$(mktemp) # create a file in /tmp
shuf $VPN_FILE > $tmp_vpnfile # randomize vpn file entries & store in /tmp
while IFS= read -r line # the input file is defined below
do
vpnsrv_stat="1"
vpnsrv=$(echo "$line" | grep -E -o '[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}')
if [ "$(scutil -r $vpnsrv)" = "Reachable" ]; then
echo "$vpnsrv is Reachable; try to 'start'"
scutil --nc start $vpnsrv
vpnsrv_stat=$?
else
echo "$vpnsrv cannot be Reached at present"
fi
if [ "$vpnsrv_stat" = "0" ]; then
echo -e "Started VPN: $vpnsrv"
break
fi
done <<< $(cat $tmp_vpnfile) # the input file is defined here!
if [ "$vpnsrv_stat" != "0" ]; then
echo -e "All available VPN connections in '$VPN_FILE' FAILED; going to exit"
exit
fiWe've touched on the usage for scutil here to help manage your VPN connections, but there are other facets to explore. For example: Assume that you need to specify a VPN based upon its physical location... how would you do that? Perhaps the simplest way would be to add a reference to the VPN's physical location in the Display name field that you entered in the System Settings, VPN panel. Adding a country code, city code (or both) to the Display name field would allow subsequent identification via (e.g.) grep.
Frequently, "external" drives are small-ish, low capacity USB "thumb drives" or SD cards that must be formatted as a "FAT" (file allocation table) filesystem. One solution is to use Disk Utility - the GUI app for disk management on macOS. However, if you're like me, you may find that Disk Utility is awkward and non-intuitive in use! Fortunately, the "command-line version" - diskutil - is a bit more straightforward... as long as you don't get distracted by the obtuse man diskutil documentation. In this case, we're not doing enything exotic - just a simple format of an SD card.
My Macbook has an SD card slot on the right-hand side. To my way of thinking, if I plug an SD card into that slot, this makes the SD card an external storage device. However, as we'll see, Apple apparently sees things differently! And so, we'll begin immediately after we've inserted the SD card into the slot:
% diskutil list external
% ## ?!?! Why is nothing listed? Let's try this instead:
% diskutil list
/dev/disk0 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *4.0 TB disk0
1: Apple_APFS_ISC Container disk2 524.3 MB disk0s1
2: Apple_APFS Container disk3 4.0 TB disk0s2
3: Apple_APFS_Recovery Container disk1 5.4 GB disk0s3
/dev/disk3 (synthesized):
#: TYPE NAME SIZE IDENTIFIER
0: APFS Container Scheme - +4.0 TB disk3
Physical Store disk0s2
1: APFS Volume Macintosh HD 9.4 GB disk3s1
2: APFS Snapshot com.apple.os.update-... 9.4 GB disk3s1s1
3: APFS Volume Preboot 5.5 GB disk3s2
4: APFS Volume Recovery 942.5 MB disk3s3
5: APFS Volume Macintosh HD - Data 124.6 GB disk3s5
6: APFS Volume VM 20.5 KB disk3s6
#------------------------------------ this is the section we need: ------------------
/dev/disk4 (internal, physical): |
#: TYPE NAME SIZE IDENTIFIER |
0: FDisk_partition_scheme *31.9 GB disk4 |
1: Windows_FAT_32 bootfs 536.9 MB disk4s1 |
2: Linux 31.4 GB disk4s2 |
#------------------------------------------------------------------------------------The diskutil list command provides information we need to proceed with formatting the SD card:
% diskutil eraseDisk FAT32 GPT disk4
Started erase on disk4
Unmounting disk
Creating the partition map
Waiting for partitions to activate
Formatting disk4s2 as MS-DOS (FAT32) with name GPT
512 bytes per physical sector
/dev/rdisk4s2: 61891008 sectors in 1934094 FAT32 clusters (16384 bytes/cluster)
bps=512 spc=32 res=32 nft=2 mid=0xf8 spt=32 hds=255 hid=411648 drv=0x80 bsec=61921280 bspf=15111 rdcl=2 infs=1 bkbs=6
Mounting disk
Finished erase on disk4
ALTERNATIVELY, to format as ExFAT:
% diskutil eraseDisk ExFAT free disk4
-- OR, IF YOU PREFER TO "name" the disk --
% diskutil eraseDisk ExFAT SDCARD disk4And that's it! Fairly simple once you ferret the needed options from Apple's documentation.
% diskutil # 'diskutil' by itself lists all available *verbs*:
Disk Utility Tool
Utility to manage local disks and volumes
Usage: diskutil [quiet] <verb> <options>, where <verb> is as follows:
list (List the partitions of a disk)
info[rmation] (Get information on a specific disk or partition)
listFilesystems (List file systems available for formatting)
listClients (List all current disk management clients)
activity (Continuous log of system-wide disk arbitration)
...
...
eraseDisk (Erase an existing disk, removing all volumes)
eraseVolume (Erase an existing volume)
reformat (Erase an existing volume with same name and type)
eraseOptical (Erase optical media (CD/RW, DVD/RW, etc.))
zeroDisk (Erase a disk, writing zeros to the media)
randomDisk (Erase a disk, writing random data to the media)
secureErase (Securely erase a disk or freespace on a volume)
partitionDisk ((re)Partition a disk, removing all volumes)
addPartition (Create a new partition to occupy free space)
splitPartition (Split an existing partition into two or more)
mergePartitions (Combine two or more existing partitions into one)
resizeVolume (Resize a volume, increasing or decreasing its size)
...
diskutil <verb> with no options will provide help on that verb # <=== NOTE!!% diskutil list disk4
/dev/disk4 (internal, physical):
#: TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *31.9 GB disk4
1: EFI EFI 209.7 MB disk4s1
2: Microsoft Basic Data GPT 31.7 GB disk4s2Note that GPT means GUID Partition Table; and if you're wondering what an EFI partition/volume is, here's the details. An alternative to GPT is Master Boot Record; if you prefer that, simply change the command above to the following:
% diskutil eraseDisk FAT32 MBR disk4This happens all the time! : You have an active SSH session in iTerm2, you get distracted or called away, and while you are away, the SSH session dies (or is closed, or whatever). If you're simply sitting, parked at the command line, there's no problem; you re-connect your SSH session, and go on your merry way. HOWEVER if you're in a 'pager' app (less... maybe reading a man page), or in your editor (vim, nano, etc), or perhaps another app, the way ahead is not so merry! Upon re-connecting the SSH session you find that "scrolling" with your mouse/glide pad now glides through your command history - instead of scrolling the entire screen up and down. I hate it when that happens!
I don't know how to stop that from happening, but I have learned how to correct it:
go to `iTerm2`, `Settings...`, and then select the `Advanced` tab.
once in the `Advanced` tab, scroll down into the `Mouse` area, and find this line:
Scroll wheel sends arrow keys when in alternate screen mode
change the setting (to the right) from "Yes" to "No"
Credit for this fix goes to @ThomasDickey, the author of the answer to this Q&A! I'd encourage you to stop by, and give him an "upvote" :)
This Daylight Savings Time often feels just ridiculous to me. And I frequently have to schedule things in UTC time because that's the TZ I use on my Linux/Unix systems. To make this a little easier, I have placed two aliases in my ~/.zshrc file:
alias set_cen='sudo systemsetup -settimezone America/Chicago'
alias set_gmt='sudo systemsetup -settimezone GMT'
After a . ~/.zshrc in my Terminal.app, I can type set_cen or set_gmt, and see the time updated in my menu bar.
Often we find ourselves needing to open a window or tab in Terminal when we are using Finder to navigate through the file system. For such a common task one might think Apple capable of facilitating a "shortcut" or other efficient method for doing this - one that works across different versions of macOS. Unfortunately, in over 15 years it seems Apple has been unable to do this!
As a backstop to Apple's lack of clarity/consistency, the following scheme is offered:
- In a
Finderwindow, navigate to a folder where you need to open aTerminalwindow/tab. - 'control(^)-click' the folder in the path bar (bottom of
Finderwindow), then either: - click "Open in Terminal" - to get a new Finder window, OR...
- if the 'control(^)-click' menu yields a
Servicesoption, you can explore that for other options
Some Notes:
-
With the
Finderwindow in focus, verify that thePath Baroption under theViewmenu is selected. -
If you have a certain app installed (e.g.
BBEdit), selecting the "Open in Terminal" option (from the 'control(^)-click' operation) may result in launching an edit window inBBEditinstead of launching a newTerminalwindow! In this case, move down to display the options underServicesinstead. (Yes - this is rather BFU!) -
If you're having trouble, the screenshots below might be helpful:
1. Verify Path Bar option selected |
2. Open a Terminal window at the path |
|---|---|
![]() |
![]() |
I'll guess this has been around for a while, but I've only recently discovered it... and as it seems useful/time-saving, I've added it here. When you've got a lot of stuff in your scrollback buffer, you can hop through it (more) quickly with this keyboard shortcut:
shift + fn + up arrow will give you a PageUp;
shift + fn + down arrow will give you a PageDown.
- OSXDaily offers a list of "command line tips"
- The Mac Observer has tips, tricks & news items.
- Q&A: Using the
atcommand in macos - Linux at, batch, atq, and atrm commands
- One Time Task Scheduling using at Command in Linux
- How to Use at and batch on Linux to Schedule Commands
- at(1) - Linux man page
- GadgetHacks has a list of Essential MacOS commands; some are actually useful.
- Terminal.app keyboard shortcuts for some recent versions of MacOS
- Q&A: Null & empty string comparison in Bash: Know the difference between
null& an empty string. - Q&A: (How to put a) Command inside if statement of bash script
- On Catalina, how can a cronjob get permission to touch files on a USB disk?
- List All Environment Variables - a nixCraft article.
- Q&A: Restoring iTerm2 to default values
- Q&A: How to export iTerm2 Profiles - the antidote?
- Keeping SSH Sessions Alive After Disconnect: ideas to help w/ SSH disconnects; incl
screen&tmux. - Using the Debug Mode in SSH to ID Connection Issues; done from client side.
- Buttloads of SSH How-To From TecMint; all sorts of uses for SSH!
- Q&A: How to create a bash script to check the SSH connection?
- Six (6) commands for Checking SSH Connections
- A script can be run by sshd when a specified user logs in; or this simpler approach.
- Set macOS
Standbyparameters. Standby mode's role in dropping SSH connections? - How to Keep Your MacBook Awake While Closed; The HTG author missed the boat on this one.
- Using
pmsetfor Power Mgmt in macOS: Some advice from the Eclectic Light Company blog. - airport – the Little Known Command Line Wireless Utility for Mac - from OSX Daily.
- A series of articles re the
networksetupcommand - from OSX Daily. networksetup- YALKCLWUM- Wilson Mar's list of macOS command-line utilities - Extensive!
- Obscure Terminal Features from the Scripting OS X blog. Obscure - but also useful!
- L’entrée à AppleScript Language Guide
- Confirmed: Apple Caught In Siri Privacy Scandal - Yes, it's true - a corporation lied :/
- Q&A: To what degree is Siri listening?
- How to Delete Siri and Dictation History in macOS Catalina No, sadly, this is not a Siri deletion how-to
- Q&A: How to delete system apps in macOS Catalina?
- Part 11 of arsTECHNICA's excellent review of Catalina explains Apple's changes to the filesystem that have made simple things difficult
- How to remove Siri from my MacBook
- Disable bunch of #$!@ in Catalina - Sadly, this fine effort now neutered for Big Sur by Apple's Autocracy
- Siri Stores Encrypted E-mails in Plain Text - Disturbing...
- Challenge: does your ten-year-old code still run? I think about this in terms of the Apple Autocracy
- Ten Years Reproducibility Challenge - I have code written for Mojave that won't run on Catalina - you?
- Switch the profile of your current terminal
- Q&A: Why does rm -f ask me for confirmation on zsh?
- Q&A: Double rm verification in zsh
- Running a task at a specified time on a Mac
- Blue Lotus Blog: Death to .DS_Store, Dec 24, 2011
- Q&A:Is there a way to prevent those pesky .DS_Store files from being ever created?
- Q&A: How to merge audio and video file in ffmpeg
- Q&A: how to make scutil login to VPN with password on Mac?


