Small information nuggets and recipies about Apple OS’s
✂️ Apple
Table of Contents
- List all registered url schemes
- Access unicode characters for keyboard symbols
- Link to Notes
- Enable Touch ID for sudo
- Remove quarantine
- File extended attributes
- Add to sudoers without needing a restart
- Create encrypted zip file
- View and change file flags
- Reset unlocking MacBook by Apple Watch
- Why does it keep waking from sleep?
- Delete old Time Machine backups
- Use Keychain for unlocking SSH private key
- Spoof MAC address
- Consult timestamps on Safari history
- Homebrew: Remove formula and its dependencies, if not in use
- Homebrew: Show installed formulae and dependencies
- Homebrew quick guide
- Homebrew: Using Caskroom sources
- Test and debug LaunchAgents and LaunchDaemons
- Resolve host from IP
- Disable/revoke disk decryption from a user
- Create user manually without disk encryption rights
- Check user definitions
- Where the modem passwords are stored
- Where the dhcp leases are stored
- Flush DNS cache
- Force Spotlight to re-index
- Remove duplicates in the “Open With” menu
- View resource forks
- MySQL server
- iPhoto speedup
- Stop nmbd
- Quit application
- “Old” style sleep mode
- Eject cd
- Text styles and substitutions
- Open man pages in PDF
- Start/Stop local FTP Server
(most recent on top)
List all registered url schemes
/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -dump URLSchemeBinding
or, to make it more readily available:
alias lsregister='/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister'
lsregister -dump URLSchemeBinding
Access unicode characters for keyboard symbols
-
You can click the ⚙️ or (•••) button > Customize List and enable additional unicode characters groups, including Code Tables > Unicode which will show the full unicode table grouped by categories.
The ⌘ ⇪⌥ ⏎ symbols are grouped under the Symbols > Technical Symbols category which you can enable for quick access
-
Interesting categories to enable:
- Symbols > Musical Symbols
- Symbols > Signs and Standard Symbols
- Symbols > Technical Symbol
Link to Notes
- To find out the id of a Note use shortcut Get URL of Note (via iBanks3)
-
Run shortcut Get URL of Note
-
Enter node
Note
and check theLNEntity
Supported Type to get the UUID, e.g.:<LNEntity: 0x123456789, identifier: NoteEntity/applenotes:note/12345678-abcd-bcde-cdef-123456789012, ...
➔
12345678-abcd-bcde-cdef-123456789012
-
Convert the UUID to ALL CAPS (for example, using Convert Case or the Pages app):
➔
12345678-ABCD-BCDE-CDEF-123456789012
-
Append it to the url sheme to open Notes:
➔
applenotes://showNote?identifier=12345678-ABCD-BCDE-CDEF-123456789012
Note: Sometimes you might get the following error:
An error occurred while running Get URL of Note
Couldn’t communicate with a helper application.
I haven’t found any way around it other than trying again some other time 🤷♂️ — restarts haven’t helped at all.
Enable Touch ID for sudo
cd /etc/pam.d/ && sudo chmod a+w sudo && vi sudo && sudo chmod a-w sudo && cd -
# sudo: auth account password session
auth sufficient pam_tid.so # <= add this line here
auth sufficient pam_smartcard.so
auth required pam_opendirectory.so
account required pam_permit.so
password required pam_deny.so
session required pam_permit.so
Remove quarantine
… “‘command’ cannot be opened because the developer cannot be verified.”
xattr -d com.apple.quarantine /usr/local/bin/cmd
File extended attributes
… list attributes
ls -l -@ file
xattr file
… show values
xattr -l file
xattr -p attribute file
Add to sudoers without needing a restart
su - admin
… add
sudo dseditgroup -o edit -a hugo -t user admin
sudo dseditgroup -o edit -a hugo -t user wheel
… delete
sudo dseditgroup -o edit -d hugo -t user admin
sudo dseditgroup -o edit -d hugo -t user wheel
Create encrypted zip file
- Creating AES256 encrypted Zip Archive Files on a Mac from the Command Line
- macosx - What encryption method is used by the zip program in macOS? - Information Security Stack Exchange
… install
brew install p7zip
… create
7za a -tzip -mem=AES256 -p secrets-encrypted.zip secrets/
7za x secrets-encrypted.zip
View and change file flags
… invisible = hidden
; visible = nohidden
$ touch seeme hideme
$ chflags hidden hideme
$ chflags nohidden seeme
$ ls -lO *me # -O is an “oh” not a “zero”
-rw-r--r-- 1 hugo staff hidden 0 Mar 12 11:28 hideme
-rw-r--r-- 1 hugo staff - 0 Mar 12 11:28 seeme
Reset unlocking MacBook by Apple Watch
- In Messages
- Preferences ➤ Accounts
- Sign Out
- Sign In
- In System Preferences
- Security & Privacy
- Check “Allow your Apple Watch to unlock you Mac”
Why does it keep waking from sleep?
- If your Mac doesn’t sleep or wake when expected - Apple Support
- Determine Why Your Mac Wakes Up From Sleep
… definition of log terms
- OHC (Open Host Controller) is usually USB or Firewire. OHC1 or OHC2 is almost certainly an external USB keyboard or mouse
- EHC (Enhanced Host Controller) is another USB interface, but can also be wireless devices and bluetooth
- USB when a USB device woke the machine up
- LID0 when you open the lid the machine wakes up from sleep
- PWRB (Power Button) which is the physical power button on your Mac
- RTC (Real Time Clock Alarm) is generally from wake-on-demand services
- Schedule sleep and wake via the Energy Saver control panel
launchd
setting- User applications
- Backups
- Other scheduled events
log show --last 1d --predicate 'eventMessage contains "Wake reason"'
log show --last 1d | grep -C15 -i "wake reason"
Delete old Time Machine backups
- macos - How can I manually delete old backups to free space for Time Machine? - Ask Different
- time machine - Remove unnecessary backups from TimeMachine to get space - Ask Different
tmutil listbackups
sudo tmutil delete /Volumes/[Disk]/Backups.backupdb/[Name]/2000-00-00-000000
sudo tmutil delete /Volumes/[Disk]/Backups.backupdb/[Name]/2000-*
Use Keychain for unlocking SSH private key
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
Spoof MAC address
openssl rand -hex 6 | sed 's/\(..\)/\1:/g; s/.$//' # make
sudo ifconfig en0 ether xx:xx:xx:xx:xx:xx # set
ifconfig en0 |grep ether # check
Consult timestamps on Safari history
- sqlite - What format is the Safari History.db history_visits.visit_time in? - Stack Overflow
- See website visit time in Safari history - Ask Different
$ sqlite3 ~/Library/Safari/History.db
sqlite> .headers on
select datetime(v.visit_time + 978307200, 'unixepoch', 'localtime') as date, v.visit_time + 978307200 as epoch, v.visit_time, i.domain_expansion, i.url
from history_items i left join history_visits v on i.id = v.history_item
order by i.id desc
limit 100;
Quick one-liner to paste into the Terminal:
sqlite3 ~/Library/Safari/History.db "select datetime(v.visit_time + 978307200, 'unixepoch', 'localtime') as date, v.title, i.url from history_items i left join history_visits v on i.id = v.history_item order by v.visit_time desc;" | less
Homebrew: Remove formula and its dependencies, if not in use
- Add an option to
brew rm
to uninstall / remove a package, including all it’s dependencies. · Issue #7465 · Homebrew/homebrew - beeftornado/homebrew-rmtree - Ruby
… installing command
brew tap beeftornado/rmtree && brew install brew-rmtree
… removing a formula
brew rmtree --dry-run formula
Homebrew: Show installed formulae and dependencies
… top-level only
brew leaves
… all dependencies
brew deps --installed [--tree]
… what uses a dependency
brew uses --installed --recursive formula
Homebrew quick guide
… installed things
brew list
… bumping version
brew update # Homebrew itself
brew outdated # Formulas
brew upgrade [$FORMULA] # Formulas
… clearing things
brew list --versions --multiple
brew cleanup -n # dry run
brew cleanup [$FORMULA]
Homebrew: Using Caskroom sources
brew tap caskroom/cask
brew cask info Caskroom/cask/rowanj-gitx
Test and debug LaunchAgents and LaunchDaemons
sudo launchctl log level debug
tail -f /var/log/system.log
sudo launchctl log level error
launchctl list [cc.ferreira.backlog.daily]
launchctl start cc.ferreira.backlog.daily
launchctl unload -w ~/Library/LaunchAgents/cc.ferreira.backlog.daily.plist
launchctl load -w ~/Library/LaunchAgents/cc.ferreira.backlog.daily.plist
Resolve host from IP
- with zeroconf / Multicast DNS / mDNS
dig +short -x 192.168.1.65 -p 5353 @224.0.0.251
Disable/revoke disk decryption from a user
- for FileVault 2
- osx - Disable a user’s ability to unlock a FileVault 2 volume at startup/login time - Ask Different
- Prevent certain accounts from unlocking FileVault 2 | TUAW - The Unofficial Apple Weblog
$ sudo su - testing
$ passwd
Changing password for charlie.
Old Password: # [enter old password here]
New Password: # [press enter]
Retype New Password: # [press enter]
- System Preferences ➤ Security & Privacy ➤ FileVault
- Enable Users …
- Set Password …
Create user manually without disk encryption rights
- for FileVault 2
sudo dscl /Local/Default -create /Users/testing
sudo dscl /Local/Default -create /Users/testing UserShell /bin/bash
sudo dscl /Local/Default -create /Users/testing RealName "Testing"
sudo dscl /Local/Default -create /Users/testing UniqueID 503
sudo dscl /Local/Default -create /Users/testing PrimaryGroupID 1000
sudo dscl /Local/Default -create /Users/testing NFSHomeDirectory /Users/testing
sudo passwd testing
Check user definitions
sudo dscl /Local/Default -read /Users/testing
Where the modem passwords are stored
cat /Library/Preferences/SystemConfiguration/preferences.plist
Where the dhcp leases are stored
cat /var/db/dhcpd_leases
Flush DNS cache
sudo dscacheutil -flushcache
Force Spotlight to re-index
sudo mdutil -E /
Remove duplicates in the “Open With” menu
cd /System/Library/Frameworks/ApplicationServices.framework/\Frameworks/LaunchServices.framework/Support/
lsregister -kill -r -domain local -domain system -domain user
View resource forks
# DEPRECATED: ls -l path/to/file/rsrc
MySQL server
… MacPorts
su - admin -c "sudo mysql.server start | stop | …"
… Homebrew
su - admin; mysql.server start | stop | …
iPhoto speedup
cd Pictures/iPhoto\ Library/
for db in *.db; do
sqlite3 $db "vacuum;"
done
Stop nmbd
sudo launchctl unload /System/Library/LaunchDaemons/nmbd.plist
Quit application
osascript -e 'tell app "iCal" to quit'
“Old” style sleep mode
pmset -g | grep hibernatemode
sudo pmset -a hibernatemode 0
Eject cd
drutil tray eject
Text styles and substitutions
open ~/Library/Preferences/.GlobalPreferences.plist
# See `NSFavoriteStyles`
# See `NSUserReplacementItems`
Open man pages in PDF
man -t opensnoop | open -f -a /Applications/Preview.app
Start/Stop local FTP Server
sudo -s launchctl load -w /System/Library/LaunchDaemons/ftp.plist
sudo -s launchctl unload -w /System/Library/LaunchDaemons/ftp.plist