Create a gist now

Instantly share code, notes, and snippets.

@kch /safari.rb
Created May 31, 2013

What would you like to do?
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