This post contains a hand-full of my favorite macOS commands and utilities that you can use from the terminal.
If you want to know more about the commands, be sure to run man <cmd>
to read the manual and find out more.
exiftool
installed via brew
Show exif data
exiftool -a -G1 -s -api QuickTimeUTC=1 -time:all -api RequestAll=2 <file>
Fix for iCloud videos incorrect creation/captured date
exiftool '-FileCreateDate<Keys:CreationDate' <file>
Open a Quick Look preview
qlmanage -p <file>
Convert SVG to PNG
qlmanage -t -s 1024x1024 -o <file>.png <file>.svg
imagemagick
installed via brew
Convert .heic
images
magick mogrify -monitor -format jpg *.heic
Limit file size
convert original.jpg -define jpeg:extent=2MB output.jpg
Read more at https://www.digitalocean.com/community/tutorials/workflow-resizing-images-with-imagemagick.
Quickly access file metadata
mdls <file>
Resize image, ignore aspect ratio
sips -z <height> <width> <file>
Resize largest side of image, respect aspect ratio
sips -Z <size> <image>
Rotate image
sips -r <degrees> <image>
You can use sips together with iconutil
to generate an .icns
file for your app from a 1024x1024 PNG:
mkdir MyIcon.iconset
cp Icon1024.png MyIcon.iconset/icon_512x512@2x.png
sips -z 16 16 Icon1024.png --out MyIcon.iconset/icon_16x16.png
sips -z 32 32 Icon1024.png --out MyIcon.iconset/icon_16x16@2x.png
sips -z 32 32 Icon1024.png --out MyIcon.iconset/icon_32x32.png
sips -z 64 64 Icon1024.png --out MyIcon.iconset/icon_32x32@2x.png
sips -z 128 128 Icon1024.png --out MyIcon.iconset/icon_128x128.png
sips -z 256 256 Icon1024.png --out MyIcon.iconset/icon_128x128@2x.png
sips -z 256 256 Icon1024.png --out MyIcon.iconset/icon_256x256.png
sips -z 512 512 Icon1024.png --out MyIcon.iconset/icon_256x256@2x.png
sips -z 512 512 Icon1024.png --out MyIcon.iconset/icon_512x512.png
iconutil -c icns MyIcon.iconset
As a bonus, generate an .ico
with ffmpeg
:
ffmpeg -i MyIcon.iconset/icon_256x256.png icon.ico
Double bonus, you can also input an SVG if you use qlmanage
first instead of the cp
command:
qlmanage -t -s 1024x1024 -o MyIcon.iconset/Icon1024.png icon.svg
Running caffeinate
with no arguments prevents your Mac sleeping as long as it is running.
Prevents sleep for X number of seconds
caffeinate -u -d -t <seconds>
Automatically exit caffeinate once the specified process exits.
caffeinate -w <pid>
Prevent sleep until the given command exits
caffeinate <command>
pbcopy
copy to the clipboard
<command> | pbcopy
pipe stdout to clipboard
pbpaste
put contents of the clipboard to stdout
Open file with associated app
open <file>
Open the file with given application
open -a <app> <file>
Open current directory in new Finder window
open .
Open a url in the default browser
open <url>
Copy a file / directory
ditto <source> <destination>
jq
installed via brew
Format JSON from the command line.
cat <file.json> | jq
Format JSON that is in the clipboard
pbcopy | jq | pbpaste
textutil
can convert files to and from Microsoft Word, plain text, rich text, and HTML formats.
converts journal.doc into journal.html.
textutil -convert html <file>.doc
The possible values for -convert
are: txt
, html
, rtf
, rtfd
, doc
, and docx
.