~mil/sxmo-utils

e5877059ffa99e6e5eb23efc6bbdbf31155a9acf — Miles Alan 1 year, 6 months ago 22d974f 1.0.5
Lots of bugfixes related to calling/modem and various script fixes
M programs/sxmo_megiaudioroute.c => programs/sxmo_megiaudioroute.c +1 -1
@@ 351,7 351,7 @@ static struct audio_setup audio_setup = {

        .hp_vol = 15,
        .spk_vol = 15,
        .ear_vol = 31,
        .ear_vol = 15,
        .mic_gain = 1,
};


M programs/sxmo_vibratepine.c => programs/sxmo_vibratepine.c +1 -1
@@ 68,7 68,7 @@ int main(int argc, char* argv[])

  int durationMs, strength;

  if (argc < 1) {
  if (argc < 2) {
    usage();
    return 1;
  }

M scripts/appscripts/sxmo_youtube.sh => scripts/appscripts/sxmo_youtube.sh +31 -19
@@ 1,23 1,35 @@
#!/usr/bin/env sh
pidof svkbd-sxmo || svkbd-sxmo &
SEARCHTERMS="$(
  echo "Search term" |
  dmenu -p "Yt Search" -c -l 10 -fn Terminus-20
)"
pkill svkbd-sxmo
menu() {
  pidof svkbd-sxmo || svkbd-sxmo &
  SEARCHTERMS="$(
    echo "Search term" |
    dmenu -p "Yt Search" -c -l 10 -fn Terminus-20
  )"
  pkill svkbd-sxmo

IDIOTRESULTS="$(idiotbox-cli $SEARCHTERMS)"
RESULT="$(
        echo "$IDIOTRESULTS" |
        grep -Ev '^(Channelid|Atom feed|Channel title|Published|Viewcount|Userid):' |
        sed -E 's/^(URL|Duration):\s+/\t/g' |
        tr -d '\n' |
        sed 's/===/\n/g' |
        gawk -F'\t' '{ print $3 " " $1 " " $2}' |
        dmenu -c -l 10 -fn Terminus-20
)"
  IDIOTRESULTS="$(idiotbox-cli $SEARCHTERMS)"
  RESULT="$(
          echo "$IDIOTRESULTS" |
          grep -Ev '^(Channelid|Atom feed|Channel title|Published|Viewcount|Userid):' |
          sed -E 's/^(URL|Duration):\s+/\t/g' |
          tr -d '\n' |
          sed 's/===/\n/g' |
          gawk -F'\t' '{ print $3 " " $1 " " $2}' |
          dmenu -c -l 10 -fn Terminus-20
  )"

[[ "CLOSE_MENU" == "$RESULT" ]] && exit 0
  [[ "CLOSE_MENU" == "$RESULT" ]] && exit 0
  URL=$(echo "$RESULT" | awk -F " " '{print $NF}')
}

URL=$(echo "$RESULT" | awk -F " " '{print $NF}')
st -e mpv --ytdl-format='[height<420]' $@ "$URL"
video() {
  menu
  st -e mpv -v --ytdl-format='[height<420]' "$URL"
}

audio() {
  menu
  st -e mpv -v --no-video "$URL"
}

$@

M scripts/core/sxmo_appmenu.sh => scripts/core/sxmo_appmenu.sh +14 -13
@@ 10,11 10,11 @@ programchoicesinit() {
    Apps               ^ 0 ^ sxmo_appmenu.sh applications
    Volume ↑           ^ 1 ^ sxmo_vol.sh up
    Volume ↓           ^ 1 ^ sxmo_vol.sh down
    Dialer             ^ 1 ^ sxmo_modemcall.sh dial
    Texts              ^ 0 ^ sxmo_readtexts.sh
    Dialer             ^ 0 ^ sxmo_modemcall.sh dial
    Texts              ^ 0 ^ sxmo_modemtext.sh
    Camera             ^ 0 ^ sxmo_camera.sh
    Wifi               ^ 0 ^ st -e "nmtui"
    System Config      ^ 0 ^ sxmo_appmenu.sh control
    Config             ^ 0 ^ sxmo_appmenu.sh config
    Logout             ^ 0 ^ pkill -9 dwm
  ")" && WINNAME=Sys



@@ 32,24 32,25 @@ programchoicesinit() {
  # Scripts menu
  echo $WMCLASS | grep -i "scripts" && CHOICES="$(echo "
    Timer           ^ 0 ^ sxmo_timermenu.sh
    Youtube         ^ 0 ^ sxmo_youtube.sh
    Youtube (Audio) ^ 0 ^ sxmo_youtube.sh --no-video
    Youtube         ^ 0 ^ sxmo_youtube.sh video
    Youtube (Audio) ^ 0 ^ sxmo_youtube.sh audio
    Weather         ^ 0 ^ sxmo_weather.sh
    RSS             ^ 0 ^ sxmo_rss.sh
  ")" && WINNAME=Scripts && return

  # System Control menu
  echo $WMCLASS | grep -i "control" && CHOICES="$(echo "
  echo $WMCLASS | grep -i "config" && CHOICES="$(echo "
    Volume ↑                   ^ 1 ^ sxmo_vol.sh up
    Volume ↓                   ^ 1 ^ sxmo_vol.sh down
    Brightesss ↑               ^ 1 ^ sxmo_brightness.sh up
    Brightness ↓               ^ 1 ^ sxmo_brightness.sh down
    Modem $(pgrep -f sxmo_modemmonitor.sh >/dev/null && echo -n "On → Off" || echo -n "Off → On") ^ 1 ^ sxmo_modemmonitortoggle.sh
    Modem Info                 ^ 1 ^ sxmo_modeminfo.sh
    Modem Info                 ^ 0 ^ sxmo_modeminfo.sh
    Modem Log                  ^ 0 ^ sxmo_modemlog.sh
    Rotate                     ^ 1 ^ rotate
    Wifi                       ^ 0 ^ st -e "nmtui"
    Upgrade Pkgs               ^ 0 ^ st -e sxmo_upgrade.sh
  ")" && WINNAME=Control && return
  ")" && WINNAME=Config && return

  # MPV
  echo $WMCLASS | grep -i "mpv" && CHOICES="$(echo "


@@ 68,8 69,8 @@ programchoicesinit() {

  #  St
  echo $WMCLASS | grep -i "st-256color" && CHOICES="$(echo "
      Pastecomplete   ^ 0 ^ key Ctrl+Shift+u
      Copycomplete    ^ 0 ^ key Ctrl+Shift+i
      Type complete   ^ 0 ^ key Ctrl+Shift+u
      Copy complete   ^ 0 ^ key Ctrl+Shift+i
      Paste           ^ 0 ^ key Ctrl+Shift+v
      Zoom +          ^ 1 ^ key Ctrl+Shift+Prior
      Zoom -          ^ 1 ^ key Ctrl+Shift+Next


@@ 117,7 118,7 @@ programchoicesinit() {
      Zoom -            ^ 1 ^ key Ctrl+minus
      History  ←        ^ 1 ^ key Alt+Left
      History  →        ^ 1 ^ key Alt+Right
  ")" && WINNAME=netsurf && return
  ")" && WINNAME=firefox && return

  # Foxtrot GPS
  echo $WMCLASS | grep -i foxtrot && CHOICES="$(echo "


@@ 162,8 163,8 @@ rotate() {
}

key() {
  xdotool windowactivate $WIN
  xdotool key --clearmodifiers $1
  xdotool windowactivate "$WIN"
  xdotool key --clearmodifiers "$1"
  #--window $WIN
}


M scripts/core/sxmo_brightness.sh => scripts/core/sxmo_brightness.sh +2 -1
@@ 4,7 4,8 @@

MAX=$(cat $DEV/max_brightness)
MIN=2
STEP=$(echo "($MAX - $MIN) / 10" | bc)
MINSTEP=1
STEP=$(echo "($MAX - $MIN) / 10" | bc | xargs -ISTP echo -e "$MINSTEP\nSTP" | sort -r | head -n1)

setdelta() {
  sxmo_setpinebacklight $(

M scripts/core/sxmo_dmenu_with_kb.sh => scripts/core/sxmo_dmenu_with_kb.sh +1 -1
@@ 1,6 1,6 @@
#!/usr/bin/env sh

pidof svkbd-sxmo >&2 || svkbd-sxmo &
OUTPUT="$(cat | dmenu -t $@)"
OUTPUT="$(cat | dmenu $@)"
pkill svkbd-sxmo >&2
echo "$OUTPUT"

M scripts/core/sxmo_pipecomplete.sh => scripts/core/sxmo_pipecomplete.sh +16 -19
@@ 1,38 1,35 @@
#!/usr/bin/env sh
INPUT="$(cat)"
STWIN="$(xprop -root | sed -n '/^_NET_ACTIVE_WINDOW/ s/.* //p')"

pidof svkbd-sxmo || svkbd-sxmo &

capfirstchar() {
  awk -F  -vOFS= {$1=toupper($1);print $0}
menu() {
  pidof svkbd-sxmo || svkbd-sxmo &
  RESULT="$(
    echo "$(
      echo "Close Menu" &&
      echo "$INPUT" | grep -Eo '\S+' | tr -d '[:blank:]' | sort | uniq
    )" | dmenu -p "$PROMPT" -l 10 -i -c -fn Terminus-20
  )"
  pkill svkbd-sxmo
}

RESULT="$(
        echo "$(
                echo "Close Menu" &&
                echo "$INPUT" |\
                  grep -Eo '\S+' |\
                  tr -d '[:blank:]' |\
                  sort |\
                  uniq
        )" | dmenu -p $(echo $1 | capfirstchar) -l 10 -i -c -fn Terminus-20
)"

pkill svkbd-sxmo

copy() {
  PROMPT=Copy
  menu
  if [[ "$RESULT" = "Close Menu" ]]; then
    exit 0
  else
    echo "$RESULT" | xsel -i
    echo "$RESULT" | xclip -i
  fi
}

type() {
  PROMPT=Type
  menu
  if [[ "$RESULT" = "Close Menu" ]]; then
    exit 0
  else
    xdotool type "$RESULT"
    xdotool type --window $STWIN "$RESULT"
  fi
}


M scripts/core/sxmo_statusbar.sh => scripts/core/sxmo_statusbar.sh +6 -1
@@ 1,6 1,11 @@
#!/usr/bin/env sh
pgrep -f sxmo_statusbar.sh | grep -v $$ | xargs kill -9

audiodevice() {
  amixer sget Earpiece | grep -E [[]on[]] && echo Earpiece > /dev/null && return
  amixer sget Headphone > /dev/null && echo Headphone || echo Speaker
}

UPDATEFILE=/tmp/sxmo_bar
touch $UPDATEFILE



@@ 19,7 24,7 @@ do

        # Volume
        VOL=$(
                echo "$(amixer sget Headphone || amixer sget Speaker)" |
                echo "$(audiodevice)" |
                grep -oE '([0-9]+)%' |
                tr -d ' %' |
                awk '{ s += $1; c++ } END { print s/c }'  |

M scripts/core/sxmo_vol.sh => scripts/core/sxmo_vol.sh +4 -0
@@ 1,5 1,6 @@
#!/usr/bin/env sh
device() {
  amixer sget Earpiece | grep -E '[[]on[]]' > /dev/null && echo Earpiece && return
  amixer sget Headphone > /dev/null && echo Headphone || echo Speaker
}



@@ 22,5 23,8 @@ down() {
  amixer set $(device) 1-
  notify
}
setvol() {
  amixer set $(device) $1
}

$@

M scripts/modem/sxmo_modemcall.sh => scripts/modem/sxmo_modemcall.sh +70 -31
@@ 1,14 1,39 @@
#!/usr/bin/env sh
LOGDIR=/home/$USER/.sxmo

err() {
	echo $1 | dmenu -fn Terminus-20 -c -l 10
	exit 1
	echo -e "$1" | dmenu -fn Terminus-20 -c -l 10
	kill $$
}

modem_n() {
  mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2
}

contacts() {
	cat $LOGDIR/modemlog.tsv | cut -f3 | sort | uniq | awk NF
}


modem_cmd_errcheck() {
	ARGS="$@"
	RES="$(sudo mmcli $ARGS 2>&1)"
	[[ $? -eq 0 ]] || err "Problem executing mmcli command!\n$RES"
	echo $RES
}

vid_to_number() {
  sudo mmcli -m $(modem_n) -o $1 -K | grep call.properties.number | cut -d ':' -f2 | tr -d  ' '
}

log_event() {
	EVT_HANDLE="$1"
	EVT_VID="$2"
	NUMBER="$(vid_to_number $EVT_VID)"
	TIME="$(date --iso-8601=seconds)"
	echo -ne "$TIME\t$EVT_HANDLE\t$NUMBER\n" >> $LOGDIR/modemlog.tsv
}

toggleflag() {
  TOGGLEFLAG=$1
  shift


@@ 25,13 50,15 @@ toggleflag() {
}

dialmenu() {
  NUMS=$(ls -1 ~/.sxmo || "")
  CONTACTS="$(contacts)"
	NUMBER="$(
		echo -e "$NUMS\nTest Number 804-222-1111" | 
		dmenu -l 10 -p Number -c -fn Terminus-20 |
		echo -e "Close Menu\n$CONTACTS\nTest Number 804-222-1111" | 
		sxmo_dmenu_with_kb.sh -l 10 -p Number -c -fn Terminus-20 |
		awk -F' ' '{print $NF}' |
		tr -d -
	)"
	echo $NUMBER | grep "Close Menu" && kill $$

	echo "Attempting to dial: $NUMBER" >&2
	VID="$(
		sudo mmcli -m $(modem_n) --voice-create-call "number=$NUMBER" | grep -Eo Call/[0-9]+ | grep -oE [0-9]+


@@ 43,32 70,40 @@ dialmenu() {

startcall() {
  VID="$1"
  sudo mmcli --voice-status -o $VID
	sudo mmcli -m $(modem_n) -o $VID --start | grep "successfully started" || err "Couldn't start call!"
  #modem_cmd_errcheck --voice-status -o $VID
	modem_cmd_errcheck -m $(modem_n) -o $VID --start
	log_event "call_start" $VID
}

acceptcall() {
  VID="$1"
  echo "Attempting to pickup VID $VID"
  sudo mmcli --voice-status -o $VID
	sudo mmcli -m $(modem_n) -o $VID --accept | grep "successfully" || err "Couldn't accept call!"
  #sudo mmcli --voice-status -o $VID
	modem_cmd_errcheck -m $(modem_n) -o $VID --accept
	log_event "call_pickup" $VID
}

hangup() {
  VID=$1
  sudo mmcli -m $(modem_n) -o $VID --hangup | grep "successfully hung up" || err "Failed to hangup the call?"
  modem_cmd_errcheck -m $(modem_n) -o $VID --hangup
	log_event "call_hangup" $VID
	err "Call hungup ok"
  exit 1
}

incallmenu() {
  DMENUIDX=0
  VID="$1"
  NUMBER=$(mmcli -m $(modem_n) -o $VID -K | grep call.properties.number | cut -d ':' -f2 | tr -d  ' ')
  # E.g. Run once w/o -2, and then run once with -2
  FLAGS="-e -m"
  sxmo_megiaudioroute $FLAGS
  FLAGS="$FLAGS -2"
  sxmo_megiaudioroute $FLAGS
  NUMBER="$(vid_to_number $VID)"

  # E.g. There's some bug with the modem that' requires us to toggle the
  # DAI a few times before starting the call for it to kick in
  FLAGS=" "
  FLAGS="$(toggleflag "-e" "$FLAGS")"
  FLAGS="$(toggleflag "-m" "$FLAGS")"
  FLAGS="$(toggleflag "-2" "$FLAGS")"
  FLAGS="$(toggleflag "-2" "$FLAGS")"
  FLAGS="$(toggleflag "-2" "$FLAGS")"

  while true
  do


@@ 79,19 114,20 @@ incallmenu() {
    echo -- "$FLAGS" | grep -- "-s" && TSPEAKER="Speakerphone Off" || TSPEAKER="Speakerphone On"

    CHOICES="$(echo -ne '
        Volume ↑ ^ sxmo_vol.sh up
        Volume ↓ ^ sxmo_vol.sh down
        TMUTE ^ FLAGS="$(toggleflag "-m" "$FLAGS")"
        TECHO ^ FLAGS="$(toggleflag "-z" "$FLAGS")"
        TEARPIECE ^ FLAGS="$(toggleflag "-e" "$FLAGS")"
        TLINEJACK ^ FLAGS="$(toggleflag "-h" "$FLAGS")"
        TSPEAKER ^ FLAGS="$(toggleflag "-s" "$FLAGS")"
        DTMF Tones ^ dtmfmenu $VID
        Hangup ^ hangup $VID
        Volume ↑    ^ sxmo_vol.sh up
        Volume ↓    ^ sxmo_vol.sh down
        TMUTE       ^ FLAGS="$(toggleflag "-m" "$FLAGS")"
        TECHO       ^ FLAGS="$(toggleflag "-z" "$FLAGS")"
        TEARPIECE   ^ FLAGS="$(toggleflag "-e" "$FLAGS")"
        TLINEJACK   ^ FLAGS="$(toggleflag "-h" "$FLAGS")"
        TSPEAKER    ^ FLAGS="$(toggleflag "-s" "$FLAGS")"
        DTMF Tones  ^ dtmfmenu $VID
        Hangup      ^ hangup $VID
        Lock Screen ^ sxmo_screenlock
      ' | sed "s/TMUTE/$TMUTE/;s/TECHO/$TECHO/;s/TEARPIECE/$TEARPIECE/;s/TLINEJACK/$TLINEJACK/;s/TSPEAKER/$TSPEAKER/"
    )"

    PICKED=""
    PICKED=$(
      echo "$CHOICES" | 
      xargs -0 echo | 


@@ 100,6 136,10 @@ incallmenu() {
      awk '{$1=$1};1' |
      dmenu -idx $DMENUIDX -l 14 -c -fn "Terminus-30" -p "$NUMBER"
    )

    # E.g. in modem watcher script we just kill dmenu if the other side hangsup
    echo "$PICKED" | grep -Ev "." && err "$NUMBER hung up the call"

    CMD=$(echo "$CHOICES" | grep "$PICKED" | cut -d '^' -f2)
    DMENUIDX=$(echo $(echo "$CHOICES" | grep -n "$PICKED" | cut -d ':' -f1) - 1 | bc)
    eval $CMD


@@ 108,19 148,18 @@ incallmenu() {

dtmfmenu() {
  VID=$1
  DMENUIDX=0
  DTMFINDEX=0
  NUMS="0123456789*#ABCD"

  while true
  do
    PICKED="$(
      echo "$NUMS" | grep -o . | sed '1 iReturn to Call Menu' |
      dmenu -l 20 -fn Terminus-20 -c -idx $DMENUIDX -p "DTMF Tone"
      dmenu -l 20 -fn Terminus-20 -c -idx $DTMFINDEX -p "DTMF Tone"
    )"
    DMENUIDX=$(echo "$NUMS" | grep -bo "$PICKED" | cut -d: -f1 | xargs -IN echo 2+N | bc)

    echo "$PICKED" | grep "Return to Call Menu" && break
    sudo mmcli -m $(modem_n) -o $VID --send-dtmf="$PICKED"
    echo "$PICKED" | grep "Return to Call Menu" && return
    DTMFINDEX=$(echo "$NUMS" | grep -bo "$PICKED" | cut -d: -f1 | xargs -IN echo 2+N | bc)
    modem_cmd_errcheck -m $(modem_n) -o $VID --send-dtmf="$PICKED"
  done
}


M scripts/modem/sxmo_modeminfo.sh => scripts/modem/sxmo_modeminfo.sh +0 -1
@@ 1,5 1,4 @@
#!/usr/bin/env sh

modem_n() {
  mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2
}

A scripts/modem/sxmo_modemlog.sh => scripts/modem/sxmo_modemlog.sh +2 -0
@@ 0,0 1,2 @@
#!/usr/bin/env sh
st -fn "Terminus-14" -e tail -f ~/.sxmo/modemlog.tsv

M scripts/modem/sxmo_modemmonitor.sh => scripts/modem/sxmo_modemmonitor.sh +47 -6
@@ 1,5 1,7 @@
#!/usr/bin/env sh
TIMEOUT=3
LOGDIR=/home/$USER/.sxmo
ACTIVECALL="NONE"

modem_n() {
  mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2


@@ 7,6 9,7 @@ modem_n() {

newcall() {
	VID="$1"
	sxmo_vibratepine 2000 &
	sxmo_setpineled green 1

	for i in $(sudo mmcli -m $(modem_n) --voice-list-calls | grep terminated | grep -oE Call\/[0-9]+ | cut -d'/' -f2); do


@@ 19,8 22,12 @@ newcall() {
		grep call.properties.number |
		cut -d ':' -f 2
	)

	TIME="$(date --iso-8601=seconds)"
	echo -ne "$TIME\tcall_ring\t$NUMBER\n" >> $LOGDIR/modemlog.tsv
	echo "$VID:$INCOMINGNUMBER" > /tmp/sxmo_incomingcall
	echo "Number: $INCOMINGNUMBER (VID: $VID)"

}

newtexts() {


@@ 35,13 42,46 @@ newtexts() {
		TIME="$(echo "$DAT" | grep sms.properties.timestamp | sed -E 's/^sms\.properties\.timestamp\s+:\s+//')"
		TEXTSIZE="$(echo $TEXT | wc -c)"

		mkdir -p ~/.sxmo/$NUM
		echo -ne "$NUM at $TIME:\n$TEXT\n\n" >> ~/.sxmo/$NUM/sms.txt
		echo -ne "$TIME\trecv_txt\t$NUM\t$TEXTSIZE chars\n" >> ~/.sxmo/$NUM/log.tsv
		mkdir -p "$LOGDIR/$NUM"
		echo -ne "Received from $NUM at $TIME:\n$TEXT\n\n" >> $LOGDIR/$NUM/sms.txt
		echo -ne "$TIME\trecv_txt\t$NUM\t$TEXTSIZE chars\n" >> $LOGDIR/modemlog.tsv
		sudo mmcli -m $(modem_n) --messaging-delete-sms=$i

		sxmo_vibratepine 300 && sleep 0.1
		sxmo_vibratepine 300 && sleep 0.1
		sxmo_vibratepine 300
	done
}

killinprogresscall() {
	echo "Kill the in progress call"
	pkill -9 dmenu
}

inprogresscallchecker() {
	# E.g. register current call in progress as ACTIVECALL
	CURRENTCALLS="$(mmcli -m $(modem_n) --voice-list-calls)"

	# E.g. if we've previously registered an ACTIVECALL, check if it
	# was terminated by the otherside, if so kill the incall script
	# and notify user
	echo "$ACTIVECALL" | grep -E '[0-9]+' && $(
		echo "$CURRENTCALLS" | 
		grep -E "Call/${ACTIVECALL}.+terminated" && 
		killinprogresscall
	)

	# Register the active call so we can check in future loops if
	# other side hung up
	ACTIVECALL="$(
		echo "$CURRENTCALLS" | 
		grep -oE "[0-9]+ (incoming|outgoing).+active" | 
		cut -d' ' -f1
	)"

	echo "Set new Activecall:<$ACTIVECALL>"
}

while true
do
	sxmo_setpineled green 0


@@ 57,10 97,11 @@ do
		grep -Eo '[0-9]+'
	)"

	echo VIDS $VOICECALLID
	echo TIDS $TEXTIDS
	echo "Check status, VIDS: $VOICECALLID, TIDS: $TEXTIDS"

	inprogresscallchecker

	echo "$VOICECALLID" | grep . && newcall "$VOICECALLID" || rm /tmp/sxmo_incomingcall
	echo "$VOICECALLID" | grep . && newcall "$VOICECALLID" || rm -f /tmp/sxmo_incomingcall
	echo "$TEXTIDS" | grep . && newtexts "$TEXTIDS"
	sleep $TIMEOUT
done

R scripts/modem/sxmo_modemsendtext.sh => scripts/modem/sxmo_modemtext.sh +43 -11
@@ 1,13 1,18 @@
#!/usr/bin/env sh
EDITOR=vis
LOGDIR=/home/$USER/.sxmo

err() {
	echo $1 | dmenu -fn Terminus-20 -c -l 10
	exit 1
	kill $$
}

modem_n() {
  mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2
	mmcli -L | grep -oE 'Modem\/([0-9]+)' | cut -d'/' -f2
}

contacts() {
	cat $LOGDIR/modemlog.tsv | cut -f3 | sort | uniq | awk NF
}

editmsg() {


@@ 19,25 24,38 @@ editmsg() {

sendmsg() {
	MODEM=$(modem_n)
	NUMBER="$1"
	TEXT="$2"
	TEXTSIZE="$(echo "$TEXT" | wc -c)"

	SMSNO=$(
		sudo mmcli -m $MODEM --messaging-create-sms="text='$2',number=$1" |
		sudo mmcli -m $MODEM --messaging-create-sms="text='$TEXT',number=$NUMBER" |
		grep -o [0-9]*$
	)
	sudo mmcli -s ${SMSNO} --send
	sudo mmcli -s ${SMSNO} --send || err "Couldn't send text message"
	for i in $(mmcli -m $MODEM --messaging-list-sms | grep " (sent)" | cut -f5 -d' ') ; do
	  sudo mmcli -m $MODEM --messaging-delete-sms=$i
	done

	TIME="$(date --iso-8601=seconds)"
	mkdir -p ~/.sxmo/$NUMBER
	echo -ne "Sent to $NUMBER at $TIME:\n$TEXT\n\n" >> $LOGDIR/$NUMBER/sms.txt
	echo -ne "$TIME\tsent_txt\t$NUMBER\t$TEXTSIZE chars\n" >> $LOGDIR/modemlog.tsv

	err "Sent text message ok"
}

main() {
sendtextmenu() {
	modem_n || err "Couldn't determine modem number - is modem online?"

	# Prompt for number
	NUMBER=$(
		echo -e "Enter Number: \nCancel" | 
		dmenu -p "Number" -fn "Terminus-20" -l 10 -c
		echo -e "\nCancel\n$(contacts)" | 
		awk NF |
		sxmo_dmenu_with_kb.sh -p "Number" -fn "Terminus-20" -l 10 -c
	)
	echo "$NUMBER" | grep -E "^Cancel$" && exit 1
	echo "$NUMBER" | grep -E '[0-9]+' || err "That doesn't seem like a valid number"

	# Compose first version of msg
	TEXT="$(editmsg $NUMBER 'Enter text message here')"


@@ 46,13 64,27 @@ main() {
	do
		CHARS=$(echo "$TEXT" | wc -c)
		CONFIRM=$(
			echo -e "Message ($CHARS) to -> $NUMBER: ($TEXT)\nEdit\nSend\nCancel" |
			echo -e "Edit Message ($TEXT)\nSend to → $NUMBER\nCancel" |
			dmenu -c -idx 1 -p "Confirm" -fn "Terminus-20" -l 10
		)
		echo "$CONFIRM" | grep -E "^Send$" && sendmsg "$NUMBER" "$TEXT" && exit 0
		echo "$CONFIRM" | grep -E "^Send" && sendmsg "$NUMBER" "$TEXT" && exit 0
		echo "$CONFIRM" | grep -E "^Cancel$" && exit 1
		echo "$CONFIRM" | grep -E "^Edit$" && TEXT="$(editmsg "$NUMBER" "$TEXT")"
		echo "$CONFIRM" | grep -E "^Edit Message" && TEXT="$(editmsg "$NUMBER" "$TEXT")"
	done
}

main
tailtextlog() {
  st -e tail -f $LOGDIR/$1/sms.txt
}

main() {
	# Display
	ENTRIES="$(echo -e "$(contacts)" | xargs -INUM echo NUM logfile)"
	ENTRIES="$(echo -e "Close Menu\nSend a Text\n$ENTRIES")"
	NUMBER="$(echo -e "$ENTRIES" | dmenu -p Texts -c -fn Terminus-20 -l 10)"
	echo $NUMBER | grep "Close Menu" && exit 1
	echo $NUMBER | grep "Send a Text" && sendtextmenu && exit 1
	tailtextlog "$(echo $NUMBER | sed 's/ logfile//g')"
}

main
\ No newline at end of file

D scripts/modem/sxmo_readtexts.sh => scripts/modem/sxmo_readtexts.sh +0 -8
@@ 1,8 0,0 @@
#!/usr/bin/env sh
DIR=/home/$USER/.sxmo

# Warn for no texts
ls -1 $DIR | wc -l | grep -E '^0$' && echo "No texts!" | dmenu -fn Terminus-20 -l 10 -c && exit 1

# Display
ls -1 $DIR | dmenu -p Messages -c -fn Terminus-20 -l 10 | xargs -INUMBER st -e tail -f $DIR/NUMBER/sms.txt
\ No newline at end of file