Skip to content

Instantly share code, notes, and snippets.

@shokai
Last active June 16, 2023 03:22
Show Gist options
  • Save shokai/9120415 to your computer and use it in GitHub Desktop.
Save shokai/9120415 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
@mactkg
Copy link

mactkg commented Jun 16, 2023

It still works on 12.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment