Skip to content

Instantly share code, notes, and snippets.

@kch
Created May 31, 2013 16:04
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 kch/5686026 to your computer and use it in GitHub Desktop.
Save kch/5686026 to your computer and use it in GitHub Desktop.
Enable private browsing mode, open a new page in Safari for the given URL.
#!/usr/bin/env ruby
($stderr.puts(DATA.read.gsub("$0", File.basename($0))); exit 1) if ARGV.length != 1
require 'appscript'
safari_app = Appscript.app("Safari")
safari_process = Appscript.app('System Events').processes['Safari']
safari_app.activate
private_browsing_menu_item = safari_process
.menu_bars.first
.menu_bar_items['Safari']
.menus['Safari']
.menu_items['Private Browsing']
private_browsing_enabled = !private_browsing_menu_item.attributes['AXMenuItemMarkChar'].value.get.nil?
private_browsing_menu_item.click unless private_browsing_enabled
safari_app.open_location(ARGV[0])
__END__
Enable private browsing mode, open a new page in Safari for the given URL.
Usage:
$0 <URL>
Example:
$0 http://heroku.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment