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 = "  if count of window is 0\n    return null\n  else\n    return source of (\#{where})\n  end\n  CODE\n  Osascript::__asrun(code, 'Safari')\nend\n"

.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 = "  if count of window is 0\n    return null\n  else\n    return text of (\#{where})\n  end\n  CODE\n  Osascript::__asrun(code, 'Safari')\nend\n"

.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 = "  if count of window is 0\n    return null\n  else\n    return URL of (\#{where})\n  end\n  CODE\n  Osascript::__asrun(code, 'Safari')\nend\n"

.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 = "  if count of window is 0\n    make new document\n  end \n  set the URL of \#{where} to \\\"\#{url}\\\"\n  CODE\n  Osascript::__asrun(code, 'Safari')\nend\n"

.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 = "  do Javascript \"\#{code}\" in \#{where}\n  CODE\n  Osascript::__asrun(code, 'Safari')\nend\n"

.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 = "  if count of window is 0\n    return null\n  else\n    return name of (\#{where})\n  end\n  CODE\n  Osascript::__asrun(code, 'Safari')\nend\n"