Module: DesktopHelper

Defined in:
lib/sapis/desktop_helper.rb

Constant Summary collapse

CLIPBOARD_COMMAND =
"xi"

Instance Method Summary collapse

Instance Method Details

#desktop_notification(text) ⇒ Object



45
46
47
# File 'lib/sapis/desktop_helper.rb', line 45

def desktop_notification(text)
  `notify-send #{text.shellescape}`
end

#display_dialog(text) ⇒ Object

Displays an OK/Cancel dialog.

Returns true for OK, false for Cancel/Esc.



35
36
37
38
39
40
41
42
43
# File 'lib/sapis/desktop_helper.rb', line 35

def display_dialog(text)
  quoted_text = '"' + text.gsub('"', '\"').gsub("'", "'\\\\''") + '"'

  if SystemHelper.mac?
    `osascript -e 'tell app "System Events" to display dialog #{quoted_text}'`.strip == 'button returned:OK'
  else
    system("zenity --question --text=#{quoted_text}")
  end
end

#set_clipboard_text(text) ⇒ Object



27
28
29
# File 'lib/sapis/desktop_helper.rb', line 27

def set_clipboard_text(text)
  IO.popen(CLIPBOARD_COMMAND, 'w') { |io| io << text }
end