Class: Osascript::Safari

Inherits:
Object
  • Object
show all
Defined in:
lib/osascript/Safari.rb

Class Method Summary collapse

Class Method Details

.document_source_codeObject

+options tab (for instance : options = ‘tab 2 of window 1’).

Returns:

  • the HTML source code of front document or of the



85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/osascript/Safari.rb', line 85

def document_source_code
  options ||= {}
  where = options[: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_textObject

+options tab (for instance : options = ‘tab 2 of window 1’).

Returns:

  • the text displayed of front document or of the



69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/osascript/Safari.rb', line 69

def document_text
  options ||= {}
  where = options[: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’).

Returns:

  • the URL of front document or of the options



53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/osascript/Safari.rb', line 53

def get_url(options = nil)
  options ||= {}
  where = options[: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, options = nil)
  options ||= {}
  where = 
    if options[: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, options = nil)
  options ||= {}
  where = options[: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.

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(options = nil)
  options ||= {}
  where = options[: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