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 = <<~CODE
  repeat 10 times
    try
      set doc to first document whose path is "#{filepath}"
      return true
    on error errMsg
      delay 0.5
    end try
  end repeat
  return false
  CODE
  retour = Osascript::__asrun(code, 'Preview')
  return retour == 'true'
end

.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(<<~CODE)
    tell application "Preview"
      set names to name of every document
    end tell
    set text item delimiters to {"', '"}
    set names to names as text
    set text item delimiters to {}
    return "['" & names & "']"
  CODE
  # puts "liste = #{liste.inspect}"
  return liste == "['']" ? [] : eval(liste)
end

.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(<<~CODE)
    tell application "Preview"
      set paths to path of every document
    end tell
    set text item delimiters to {"', '"}
    set paths to paths as text
    set text item delimiters to {}
    return "['" & paths & "']"
  CODE
  # puts "liste = #{liste.inspect}"
  return liste == "['']" ? [] : eval(liste)
end

.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