UBports Robot Logo UBports Forum
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login
    1. Home
    2. Quaigon_Jim
    3. Posts
    Q
    Offline
    • Profile
    • Following 0
    • Followers 0
    • Topics 1
    • Posts 4
    • Groups 0

    Posts

    Recent Best Controversial
    • RE: Execute a command when an SMS is received?

      @AlainW94 Thanks, this looks promising.

      posted in OS
      Q
      Quaigon_Jim
    • RE: Execute a command when an SMS is received?

      @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 😕

      posted in OS
      Q
      Quaigon_Jim
    • RE: Execute a command when an SMS is received?

      @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

      posted in OS
      Q
      Quaigon_Jim
    • Execute a command when an SMS is received?

      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

      posted in OS
      Q
      Quaigon_Jim