% vnc start
% vnc stop
enable/disable VNC on Mac OSX (testing with OSX 10.9)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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
It still works on 12.6