Skip to content

Instantly share code, notes, and snippets.

@mattfelsen
Last active August 21, 2016 02:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattfelsen/9dce6913b4e034045a13 to your computer and use it in GitHub Desktop.
Save mattfelsen/9dce6913b4e034045a13 to your computer and use it in GitHub Desktop.
Useful OS X command line system stuff

Number of connected displays

system_profiler SPDisplaysDataType | grep Resolution | wc -l | sed 's/ //g'

Whether the system is sleeping or not

1 is alseep, 4 is not sleeping

ioreg -n IODisplayWrangler | grep -i IOPowerManagement | perl -pe 's/^.*DevicePowerState\"=([0-9]+).*$/\1/'

Set or check scheduled sleep/shutdown/wake settings

pmset repeat sleep MTWRFSU 01:00:00 wakeorpoweron MTWRFSU 08:00:00
pmset -g sched
pmset repeat cancel

Volume

Get/set volume level or mute state. Range is 0-100

osascript -e 'output volume of (get volume settings)'
osascript -e 'set volume output volume 50'

osascript -e 'output muted of (get volume settings)'
osascript -e 'set volume output muted true'

Enable screen sharing

sudo defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool false
sudo launchctl load -w /System/Library/LaunchDaemons/com.apple.screensharing.pl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment