MacOS Brain

screenshots

install brew and other tools

Copy the script from here and paste into the terminal.

shell
brew doctor
brew install nodejs

cleanup unused applications

brew install pearcleaner then run Pearcleaner.app.

save image out of google docs

Shift right click on the image to get the browser’s menu instead of google docs, and then choose ‘copy’. Go to Preview and cmd-N for new to create a new image, which will use what’s in the clipboard.

source

remote access to local dev

Suppose you are developing a web app on your laptop and you want your phone to test it. Getting your phone to talk to the local webserver can be tricky depending on the local network environment. Instead use an SSH tunnel to expose a single port of your laptop as a port on a remote webserver. This is called an SSH tunnel. Assuming you already have ssh locally and a linux remote webserver.

Check the /etc/ssh/sshd_config file on your server has these turned on AllowTcpForwarding yes GatewayPorts yes and restart the ssh server if necessary with sudo systemctl restart ssh.

Then on your local computer set up the tunnel with shell ssh -R :localhost: username@server.com For example: shell ssh -R 6000:localhost:4000 me@example.com

The local webserver is on 4000. Connect to it from http://example.com:6000/.

If you are using vite you access may be blocked for security reasons. Turn on allowed hosts in your vite config file.

javascript
  server: {
    allowedHosts:['josh.earth']
  }

adjust system settings from the coammand line

Settings can be configured with the defaults command and the key representing that particular setting. See macOS defaults for more info.

ex:

shell
# read the current orientation
defaults read com.apple.dock "orientation"
# position the dock on the left side of the screen
defaults write com.apple.dock "orientation" -string "left"
# restart the Dock
killall Dock 

set the default location for screenshots

shell
# set to ~/Desktop
defaults write com.apple.screencapture "location" -string "~/Documents/Screenshots"
# restart system ui server
killall SystemUIServer

Fix SDCards and disks

Sometimes you need to reformat a disk and DiskUtility isn't cutting it. I had a recent case of an SD card I'd used to install Linux. Disk Utility could see the drive but not read the linux partitions nor erase the partitions to turn it back into a plain MS-Dos (FAT) drive. The key is to use diskutil, the command line counterpart.

List the partitions shell diskutil list Find the id for the disk you are erasing. disk4 in my case. shell diskutil eraseDisk FAT32 RASPBIAN MBRFormat disk4

audio conversion

To convert between audio files first install ffmpeg with brew install ffmpeg.

Convert wav file to mp3. the 320k is the bitrate. For smaller files try 128k. shell ffmpeg -i input.wav -codec:a libmp3lame -b:a 320k output.mp3