Class: Osascript::Preview

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

Class Method Summary collapse

Class Method Details

.document_opened?(filepath) ⇒ Boolean

Returns true si le document de path filepath est ouvert.

Returns:

  • (Boolean)

    true si le document de path filepath est ouvert



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/osascript/Preview.rb', line 16

def document_opened?(filepath)
  code = "  repeat 10 times\n    try\n      set doc to first document whose path is \"\#{filepath}\"\n      return true\n    on error errMsg\n      delay 0.5\n    end try\n  end repeat\n  return false\n  CODE\n  retour = Osascript::__asrun(code, 'Preview')\n  return retour == 'true'\nend\n"

.documents_namesArray

preview

Returns:

  • (Array)

    La liste de tous les documents ouverts dans



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/osascript/Preview.rb', line 34

def documents_names
  liste = Osascript::__asrun("    tell application \"Preview\"\n      set names to name of every document\n    end tell\n    set text item delimiters to {\"', '\"}\n    set names to names as text\n    set text item delimiters to {}\n    return \"['\" & names & \"']\"\n  CODE\n  # puts \"liste = \#{liste.inspect}\"\n  return liste == \"['']\" ? [] : eval(liste)\nend\n")

.documents_pathsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/osascript/Preview.rb', line 48

def documents_paths
  liste = Osascript::__asrun("    tell application \"Preview\"\n      set paths to path of every document\n    end tell\n    set text item delimiters to {\"', '\"}\n    set paths to paths as text\n    set text item delimiters to {}\n    return \"['\" & paths & \"']\"\n  CODE\n  # puts \"liste = \#{liste.inspect}\"\n  return liste == \"['']\" ? [] : eval(liste)\nend\n")

.open_document(filepath) ⇒ Object

Ouvre le document filepath



11
12
13
# File 'lib/osascript/Preview.rb', line 11

def open_document(filepath)
  Osascript::__asrun("open POSIX file \"#{filepath}\"", 'Preview')
end