admin管理员组文章数量:1579085
这里写自定义目录标题
- Eclectic Tips & Tricks for Mac OS
- Table of contents
- 1. How to Change Where Screenshots Are Saved?
- 1.5 A Shell Script to Rename Screenshot Files
- 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 share
- 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` is reluctant
- 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` on Catalina
- 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"
- 27. Potentially Useful Info for Re-Installing macOS
- 28. Tools for Isolating Hardware Faults in Macs
- 29. Insert Symbols in macOS
- 30. The Elusive Symbol for *Degree*
- 31. The Strange Case of `airport`
- 32. Would You Like 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
- 35. Switch the Profile in your current Terminal window
- OTHER SOURCES:
Eclectic Tips & Tricks for Mac OS
Table of contents
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
on Catalina
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”
27. Re-Installing macOS
28. Tools for Isolating Hardware Faults in Macs
29. Insert Symbols in macOS
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
OTHER SOURCES:
1. How to Change Where Screenshots Are Saved?
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
1.5 A Shell Script to Rename Screenshot Files
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
done
The 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 Shot
is used as a filter to select only Apple-named screenshots; this will exclude files with, for example,Screen Recording
in the filename - or any files you have saved in the folder with any name that doesn’t begin withScreen Shot
. awk
is 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 variableoldtimestr
date
is used to re-formatoldtimestr
into 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
) theoldfile
withnewfile
.
2. How to Prevent macOS From Sleeping?
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. ↩ ↑toc
3. How to Start (open
) an App From the macOS Command Line?
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/mail/u/0/#inbox
c. use open
to start Chrome and load GMail:
$ open -a "/Applications/Google Chrome.app" https://mail.google/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. ↑
3.5 How to open
a Network 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.app
will open to that share in Finder
.
Note: This will also work for any other supported network file system: cifs
, nfs
, etc. ↑
4. How to Schedule an App to Run At a Specified Time?
In current versions of mac os, there are (at least) three distinct approaches to scheduling:
-
cron
is the standard (as in long-standing) method for scheduling. It’s been around since the early days of Unix. Thatcron
remains 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 thecron
software they distribute with mac os;man cron
reveals that the current version oscron
in mac os ver 10.14.6 (Mojave) is vintage June 17, 2007. See the example below. -
launchd
is 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.launchd
can do more thancron
, but it’s much more difficult (even arcane) in use. Consequently, we’ll covercron
here, and pick uplaunchd
in this installment. -
at
is a bit of an outlier in the sense it’s less frequently used. As of macOS Catalina,at
is still included, and supported (in the fashion that Apple supports such things). If you’re interested, read two things:man at
and 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 ofat
isn’t as up-to-date as the one in your favorite Linux distro, but it does work as shown in the following example:at
Example:% 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
at
thing 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
mail
command. Alternatively, you may use aredirect
to send the output to a file; e.g.echo "Hello World from at" > ~/at_output.txt
cron
Example: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
open
andcron
:cron
events 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 yourcrontab
file 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 defaultcrontab
that has comments and helpful hints, but Mac OS does not.Let’s schedule our event now. Enter the following line in the
nano
editor you’ve just opened:00 12 * * * open -a "/Applications/Google Chrome.app" https://mail.google/mail/u/0/#inbox
Next, tell
nano
to write your newcrontab
by enteringctrl-o
,enter
to accept the filename, andctrl-x
to 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
open
command and the parameters that follow it in thecrontab
entry. We’ve prepended a strange-looking sequence to that:00 12 * * *
This is simply the schedule information. It tells
cron
when 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 crontab
will 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. ↑
5. How to Check the Size of a Directory?
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
↑
6. How to Check Battery Status from the Command Line?
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: true
The -g
(get) option provides data on current settings and logfiles. It can be run with normal user privileges. pmset
can 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
. ↑
7. How to Send Files to the Trash from the macos Command Line?
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. 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 copytrash
to/usr/local/bin
-
$ chmod a+rx /usr/local/bin/trash
↑
8. How to Find the Hardware Architecture and OS Version for My Mac?
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 machine
And 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_64
uname
has several other options, all described in man uname
.
And finally, suggest that you do not use this:
$ arch
i386
This 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: 18E226
Note 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_64
This 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
↑
9. How to Combine/Concatenate Multiple PDFs?
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
. ↑
10. How to Search My Command History in Terminal
?
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 withcontrol-r
. When you’ve found the command you were looking for, hit theenter
key 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, typecontrol-g
. - You can use the
history
command!history
outputs 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. ↑
11. How to Disable Auto-Booting When Opening the Macbook Lid?
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=%00
Note 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 -p
will list available options… but it’s very messy! ↑
12. How to Copy command line
Output to Pasteboard/Clipboard?
You can copy from stdout
and paste to stdin
using one of the several clipboards available.
$ ls -la | pbcopy
You 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.txt
See 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
git
repository on your Mac, there will be files that you will need to edit; e.g..gitignore
. - all
mount
ed drives and shares are listed under/Volumes
, and it is occasionally useful to see inside this hidden folder.
Fortunately, there’s a simple way to turn visibility of hidden files and folders ON
and OFF
. If you’re starting from the default condition in which hidden files and folders are NOT visible, use the CLI as follows to render them visible from within Finder
:
$ defaults write com.apple.finder AppleShowAllFiles TRUE
If you have open Finder windows, you’ll 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 Finder
Opening a new Finder
window will reveal the hidden files and folders. To return to the default:
$ defaults write com.apple.finder AppleShowAllFiles FALSE && killall Finder
↑
15. How to Recover a Bodged git
Repository?
Recently, 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/master
A few things to review beforehand! :
- execute these commands from the local directory where you want your repo to live,
- The
remote
repository is the origin you want (in my case, the remote repo at GitHub was myorigin
) - The
branch
you want to restore is themaster
branch ↑
16. How to Restore the “Lost Startup Chime”?
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=%01
More 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! ↑
17. Weird Behavior With zsh: noglob
and rm
is reluctant
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/forums/viewtopic.php?p=1528736 zsh: no matches found: https://www.raspberrypi/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/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/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
-
zsh
wants to have a “conversation” about usingrm -rf
!Irritatingly,
zsh
refuses 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
↑
18. How to Hide All Open Windows on a Desktop? (‘Show Desktop’)
fnF11 - this will toggle Show & Hide all app windows on a desktop. ↑
19. How to Set Default Editor for CLI/Terminal App
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 vi
will 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=nano
Enter 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
. ↑
20. How to See Your Environment Variables
From the command prompt:
% printenv
# or if you prefer not to clutter your terminal history:
% printenv | less
21. Where is the PATH Environment Variable Stored on MacOS?
The 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_profile
forbash
users
22. How to Enable cron
on Catalina
In Catalina, Apple has “enhanced security” by disallowing operations that have long been allowed. cron
is one of those. Restoring cron
’s privileges requires it be granted Full Disk Access in System Preferences. Doing this using the GUI is a two-step process:
-
Due to the way that apps are added to the Full Disk Access list, we must first find
cron
in Finder:- Open Finder, enter Command+Shift+G
- Enter
usr/sbin
in the dialog box. - Finder displays the contents of
usr/sbin
, scan the file listing, and find the on a namedcron
.
-
Open System Preferences app & navigate to the Privacy tab in Security & Privacy
- Select the Full Disk Access item in the listing on the left side; this populates a list of apps on the right side
- From the Finder window above, drag and drop the
cron
app into the app list on the right. Make sure it is checked to enable access.
Opinion: I wonder if the primary effect of Apple’s “enhanced security” changes in Catalina has been to put a much larger burden on some users by forcing them to activate these work-arounds to get their tasks completed? ↑
23. Getting Up to Speed on zsh
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. IMO, zsh
is a hopped-up version of bash
- a version that appeals mostly to the hyperactive, or maybe even amphetamine users. But that’s just my opinion, man. I’ll try anything once, and here’s a shortlist to get up-to-speed on 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
bash
as the default shell on Catalina - an entire article on this:
chsh -s /bin/bash
↑
24. Upgrade Xcode on High Sierra… or Why Does Apple Crap On Us?
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? ↑
25. Cleaning and Restoration of iTerm2
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.iterm2
Know 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). ↑
26. “client_loop: send disconnect: Broken pipe”
Irritating, no? If your SSH connections are dropping like flies, you can stop that by running your SSH connections under the native caffeinate
command:
% caffeinate -i ssh user@host
This should maintain an SSH connection for as long as you need it - hours, days, weeks, etc. 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. ↑
27. Potentially Useful Info for Re-Installing macOS
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. ↑
28. Tools for Isolating Hardware Faults in Macs
For hardware built prior to June, 2013, use the Apple Hardware Test
For hardware built after June, 2013, use Apple Diagnostics. ↑
29. Insert Symbols in macOS
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à. ↑
30. The Elusive Symbol for Degree
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
31. The Strange Case of airport
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. ↑
32. Would You Like to Move That File, or Copy It?
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. ↑
33. Should You Put Siri on an “iLeash”, or Put Her Down?
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!
34. Burning ISO files to DVD
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: completed
Awesome! The physical configuration ICYI:
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-GulzNlA2-1670911227125)(pix/DVD-Burn.jpeg)]
35. Switch the Profile in your current Terminal window
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
OTHER SOURCES:
- OSXDaily offers a list of “command line tips”
- The Mac Observer has tips, tricks & news items.
- Q&A: Using the
at
command 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
Standby
parameters. 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
pmset
for 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
networksetup
command - 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
版权声明:本文标题:Eclectic Tips & Tricks for Mac OS 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/dianzi/1727845415a1133030.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论