Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env ruby
- # encoding: UTF-8
- require 'appscript'
- VALID_BROWSERS = %w[ WebKit Safari ]
- # Used in my appscripts to target Safari or WebKit dynamically.
- # Returns an Appscript::Application for one of these browsers following this priority:
- # 1. is frontmost
- # 2. is running and default
- # 3. is running
- # 4. is default
- def browser
- processes = Appscript::app("System Events").processes
- target, = VALID_BROWSERS & processes[Appscript.its.frontmost.eq(true)].short_name.get
- target ||= begin
- default_browser = VALID_BROWSERS & [%x(VERSIONER_PERL_PREFER_32_BIT=yes /usr/bin/perl -MMac::InternetConfig -le 'print +(GetICHelper "http")[1]').chomp]
- running_browsers = VALID_BROWSERS & processes.short_name.get
- (running_browsers & default_browser)[0] || running_browsers[0] || default_browser[0]
- end
- Appscript::app(target) if target
- end
Add Comment
Please, Sign In to add comment