Class: Osascript::Safari
- Inherits:
-
Object
- Object
- Osascript::Safari
- Defined in:
- lib/osascript/Safari.rb
Class Method Summary collapse
- .document_source_code ⇒ Object
- .document_text ⇒ Object
-
.get_url(options = nil) ⇒ Object
tab (for instance : options = ‘tab 2 of window 1’).
-
.open_url(url, options = nil) ⇒ Object
Open URL
url
in front document or a new window ifoptions[new_window]
is true. -
.run_javascript(code, options = nil) ⇒ Object
Run a javascript code in the front document or the
options[:where]
tab. -
.window_name(options = nil) ⇒ Object
The name of the front document.
Class Method Details
.document_source_code ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/osascript/Safari.rb', line 85 def document_source_code ||= {} where = [:where] || 'front document' code = <<~CODE if count of window is 0 return null else return source of (#{where}) end CODE Osascript::__asrun(code, 'Safari') end |
.document_text ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/osascript/Safari.rb', line 69 def document_text ||= {} where = [:where] || 'front document' code = <<~CODE if count of window is 0 return null else return text of (#{where}) end CODE Osascript::__asrun(code, 'Safari') end |
.get_url(options = nil) ⇒ Object
tab (for instance : options = ‘tab 2 of window 1’).
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/osascript/Safari.rb', line 53 def get_url( = nil) ||= {} where = [:where] || 'front document' code = <<~CODE if count of window is 0 return null else return URL of (#{where}) end CODE Osascript::__asrun(code, 'Safari') end |
.open_url(url, options = nil) ⇒ Object
Open URL url
in front document or a new window if options[new_window]
is true
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/osascript/Safari.rb', line 8 def open_url(url, = nil) ||= {} where = if [:new_window] "(make new tab in window 1)" else "front document" end code = <<~CODE if count of window is 0 make new document end set the URL of #{where} to \"#{url}\" CODE Osascript::__asrun(code, 'Safari') end |
.run_javascript(code, options = nil) ⇒ Object
Run a javascript code in the front document or the options[:where]
tab.
28 29 30 31 32 33 34 35 |
# File 'lib/osascript/Safari.rb', line 28 def run_javascript(code, = nil) ||= {} where = [:where] || 'front document' code = <<~CODE do Javascript "#{code}" in #{where} CODE Osascript::__asrun(code, 'Safari') end |
.window_name(options = nil) ⇒ Object
Returns the name of the front document.
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/osascript/Safari.rb', line 38 def window_name( = nil) ||= {} where = [:where] || 'front window' code = <<~CODE if count of window is 0 return null else return name of (#{where}) end CODE Osascript::__asrun(code, 'Safari') end |