Skip to content

Instantly share code, notes, and snippets.

@renesansz
Forked from shokai/README.md
Created March 2, 2017 07:28
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 renesansz/719be6fc13ccb1fc4293967deb49f243 to your computer and use it in GitHub Desktop.
Save renesansz/719be6fc13ccb1fc4293967deb49f243 to your computer and use it in GitHub Desktop.
enable/disable VNC on Mac OSX (testing with OSX 10.9)
% vnc start
% vnc stop

termianl

#!/usr/bin/env ruby
## enable/disable VNC on Mac OSX (testing with OSX 10.9)
def show_current_status
if system "sudo launchctl list | grep com.apple.screensharing > /dev/null" and
system "sudo defaults read /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled | grep 'Disabled = 0' > /dev/null"
puts "VNC: enabled"
else
puts "VNC: disabled"
end
end
def show_help
app_name = File.basename $0
STDERR.puts "% #{app_name} start # enable VNC"
STDERR.puts "% #{app_name} stop # disable VNC"
show_current_status
end
if ARGV.empty?
show_help
exit 1
end
enable = case ARGV.shift
when "start" then true
when "stop" then false
else
show_help
exit 1
end
system "sudo defaults write /var/db/launchd.db/com.apple.launchd/overrides.plist com.apple.screensharing -dict Disabled -bool #{!enable}"
if enable
system "sudo launchctl load /System/Library/LaunchDaemons/com.apple.screensharing.plist"
else
system "sudo launchctl unload /System/Library/LaunchDaemons/com.apple.screensharing.plist"
end
show_current_status
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment