Guest User

Untitled

a guest
Jul 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.84 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # encoding: UTF-8
  3. require 'appscript'
  4.  
  5. VALID_BROWSERS = %w[ WebKit Safari ]
  6.  
  7. # Used in my appscripts to target Safari or WebKit dynamically.
  8. # Returns an Appscript::Application for one of these browsers following this priority:
  9. # 1. is frontmost
  10. # 2. is running and default
  11. # 3. is running
  12. # 4. is default
  13. def browser
  14. processes = Appscript::app("System Events").processes
  15. target, = VALID_BROWSERS & processes[Appscript.its.frontmost.eq(true)].short_name.get
  16. target ||= begin
  17. default_browser = VALID_BROWSERS & [%x(VERSIONER_PERL_PREFER_32_BIT=yes /usr/bin/perl -MMac::InternetConfig -le 'print +(GetICHelper "http")[1]').chomp]
  18. running_browsers = VALID_BROWSERS & processes.short_name.get
  19. (running_browsers & default_browser)[0] || running_browsers[0] || default_browser[0]
  20. end
  21. Appscript::app(target) if target
  22. end
Add Comment
Please, Sign In to add comment