Skip to content

Instantly share code, notes, and snippets.

@Pitriss
Created March 7, 2020 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Pitriss/39a80f1bd783c9e9c1673bdf7956dfdb to your computer and use it in GitHub Desktop.
Save Pitriss/39a80f1bd783c9e9c1673bdf7956dfdb to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# Proof of concept script for the Trinity desktop to send SMS via Kaddressbook
# Dependencies:
# * ruby 2.3 (may work in older ver, untested)
# * ruby-dbus 0.16 (may work in older ver, untested)
# * ruby-iconv 1.0.8 (may work in older ver, untested)
# * running and functional mconnect (https://github.com/bboozzoo/mconnect)
if ARGV.nil? or ARGV.size < 2 then
puts "Usage:"
puts "mconnect-sms.rb \"number\" \"path-to-file-with-sms\" [\"Any string to enable iconv\"]"
exit 1
end
number = ARGV[0]
smsfile = ARGV[1]
sms = File.read(smsfile)
if ARGV.size > 2 then
require 'iconv'
sms = Iconv.new('ascii//translit', 'utf-8').iconv(sms)
end
require "dbus"
mybus = DBus.session_bus
app = mybus["org.mconnect"]
# Handling of device manager
obj = app["/org/mconnect/manager"]
devman = obj["org.mconnect.DeviceManager"]
devices = devman.ListDevices
# Sorting out known devices
devices.each do |n|
dev = app["#{n}"]
devstat = dev["org.mconnect.Device"]
$issent = ""
if devstat["IsConnected"] and devstat["IsActive"]
smsiface = dev["org.mconnect.Device.Telephony"]
$devname = devstat["Name"]
smsiface.SendSms(number,sms)
$issent = "yes"
break
end
end
# Initialize notification
notbus = DBus::SessionBus.instance
notobj = notbus["org.freedesktop.Notifications"]["/org/freedesktop/Notifications"]
notins = notobj["org.freedesktop.Notifications"]
if $issent != "yes" then
notins.Notify("mconnect-sms.rb", 0, "button_cancel", "SMS sending failed", "Due to some error, SMS was not sent", [], [], 2000) do |ret, param|
end
exit 1
else
notins.Notify("mconnect-sms.rb", 0, "button_ok", "SMS", "SMS was sent to the device #{$devname}", [], [], 2000) do |ret, param|
end
exit 0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment