Sha256: 1003c8edec963a5025b2443abaee75cb0f5f25cc76c7f2be680b5a81ef2f6a01
Contents?: true
Size: 1.51 KB
Versions: 1
Compression:
Stored size: 1.51 KB
Contents
module Imessage class Sender def deliver(options = {text:nil, attachment:nil, contacts: []}) options[:contacts].each do |contact| _deliver(options[:text], options[:attachment], contact) end end private def _deliver(text, attachment, contact) unless text.nil? script = <<-SCRIPT on run argv set toAddress to first item of argv set message to second item of argv tell application "Messages" send message to buddy toAddress of (service 1 whose service type is iMessage) end tell end run SCRIPT `osascript -e '#{script}' '#{contact}' '#{text}'` end unless attachment.nil? script = <<-SCRIPT on run argv set toAddress to first item of argv set theFilePath to second item of argv set theFile to POSIX file theFilePath tell application "System Events" if exists file theFilePath then tell application "Messages" send theFile to buddy toAddress of (service 1 whose service type is iMessage) end tell else error "File not exist." end if end tell end run SCRIPT `osascript -e'#{script}' '#{contact}' '#{attachment}'` end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
imessage-0.2.0 | lib/imessage/sender.rb |