UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Execute a command when an SMS is received?

    Scheduled Pinned Locked Moved OS
    10 Posts 4 Posters 905 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
      Reply
      • Reply as topic
      Log in to reply
      This topic has been deleted. Only users with topic management privileges can see it.
      • Q Offline
        Quaigon_Jim
        last edited by

        I'd like to send a notification to my desktop and laptop when I receive a text message. Is this possible?

        Or more properly: what happens in the OS when an SMS is received and where would I find more information about this?

        Thanks

        1 Reply Last reply Reply Quote 0
        • dobeyD Offline
          dobey
          last edited by

          Currently, no, it is not possible. Someone had started looking at implementing support for KDE Connect, but I'm not sure how far they got.

          1 Reply Last reply Reply Quote 0
          • G Offline
            guru
            last edited by

            Something which comes into my thinking: the SMS is stored into a table on a sqllite database and if this allows triggers to fire...

            Q 1 Reply Last reply Reply Quote 2
            • Q Offline
              Quaigon_Jim @guru
              last edited by Quaigon_Jim

              @guru Thanks, I managed to hack something together, but had to install inotify-tools:

              #!/bin/bash
              
              # location of databse storing text messages (table is "text_events")
              DB="/home/phablet/.local/share/history-service/history.sqlite"
              
              # location of scripts to run when a text is received
              SCRIPTDIR="/home/phablet/bin/text.d"
              
              function check {
              
              # current time in seconds since epoch
              CURRENTTIME=$(date +%s)
              
              # get senderid (phone number) and timestamp from most recent entry in text_events table of $DB at time of modification
              SENDERID=$(sqlite3 $DB "SELECT senderid FROM text_events ORDER BY timestamp DESC LIMIT 1;")
              
              # timestamp converted to seconds since epoch
              TIMESTAMP=$(date -d$(sqlite3 $DB "SELECT timestamp FROM text_events ORDER BY timestamp DESC LIMIT 1;") +%s)
              
              # calculate difference between when text was received and $CURRENTTIME
              DIFFERENCE=$(expr $CURRENTTIME - $TIMESTAMP)
              
              if [ $DIFFERENCE -lt 2 ] && [ $SENDERID != "self" ]
              then
              # run all scripts in #SCRIPTDIR
                      run-parts $SCRIPTDIR
              else
                      :
              fi
              }
              
              # monitor $DB for changes and execute the above function if it is modified
              while inotifywait -e modify $DB; do check; done
              
              

              There are probably much better ways of going about this but it works for now 🙂

              Any pointers appreciated.

              EDIT: Terrible code updated a bit

              G 1 Reply Last reply Reply Quote 0
              • G Offline
                guru @Quaigon_Jim
                last edited by

                Check if sqllite supports triggers. If so you could attach a trigger to any table XYZ and any INSERT into that table will fire your own written piece of software.

                Q 1 Reply Last reply Reply Quote 1
                • AlainW94A Offline
                  AlainW94
                  last edited by

                  You could also monitor the system dbus, sms appears in clear text on it.

                  Sorry I can't copy paste from terminal , maybe a bug.

                  sudo dbus-monitor --system "type='signal', interface='org.ofono.MessageManager'"
                  

                  Meizu Pro 5, Meizu Pro 5, Meizu Pro 5, Meizu Pro 5 (Yes I have 4 of them)
                  Never forget that they are much more ideas inside two heads than in one...

                  G Q 2 Replies Last reply Reply Quote 1
                  • Q Offline
                    Quaigon_Jim @guru
                    last edited by Quaigon_Jim

                    @guru

                    Looks like triggers are supported but only UPDATE/INSERT/DELETE/SELECT are allowed in the trigger body (trying to use .shell gives a syntax error).

                    Relevant Stackoverflow thread

                    Close but no cigar 😕

                    1 Reply Last reply Reply Quote 0
                    • G Offline
                      guru @AlainW94
                      last edited by

                      Thanks, this is really cool. I did a test sending Testing dbus to my UBphone:

                      $ sudo dbus-monitor --system "type='signal', interface='org.ofono.MessageManager'"
                      [sudo] password for phablet: 
                      ...
                         string "Testing dbus"
                         array [
                            dict entry(
                               string "LocalSentTime"
                               variant             string "2020-01-12T20:26:33+0100"
                            )
                            dict entry(
                               string "SentTime"
                               variant             string "2020-01-12T20:26:33+0100"
                            )
                            dict entry(
                               string "Sender"
                               variant             string "+49170xxxxxxxx"
                            )
                         ]
                      ^C
                      
                      1 Reply Last reply Reply Quote 1
                      • Q Offline
                        Quaigon_Jim @AlainW94
                        last edited by

                        @AlainW94 Thanks, this looks promising.

                        1 Reply Last reply Reply Quote 0
                        • AlainW94A Offline
                          AlainW94
                          last edited by

                          Happy to help ! 👍

                          Meizu Pro 5, Meizu Pro 5, Meizu Pro 5, Meizu Pro 5 (Yes I have 4 of them)
                          Never forget that they are much more ideas inside two heads than in one...

                          1 Reply Last reply Reply Quote 1
                          • First post
                            Last post