Hi All,
I’m trying to write a script, that gets the phone number of the last received SMS message in the inbox. I’m running 6.45.9.
If I run /tool sms inbox print I can see messages. Looking at other forum posts it looks like /tool sms inbox find and /tool sms inbox get $i phone (where is presume $i is the id of the message) should be work but running those commands in the terminal returns no results. What am I missing?
I was planning on using /tool sms inbox print count-only to count the messages, subtract 1 (as ID’s start form 0) and then pass that to /tool sms inbox get $i phone.
Any assistance would be appreciated.
Many thanks
More research suggests /tool sms inbox get $i phone doesn’t use the index so using my count - 1 method won’t work .
However /tool sms inbox find still returns nothing
Try this:
:global lastIx (:len [/tool sms inbox] - 1)
:global lastNum [/tool sms inbox get number=$lastIx phone]
:put $lastNum
…
Update: fixed first line as it had a typo
The SMS inbox is a 2D array, tips on how to work with and get parameter values from arrays can be found in the Scripting Tips and Tricks section of the wiki, specifically sections 5. Get values for properties if ‘get’ command is not available and 6. Always check what value and type command returns provide useful information for this situation.
To answer the original question directly, the quick and dirty one liner for testing in the terminal would be -
:put ([:pick [/tool sms inbox print as-value] ([/tool sms inbox print count-only] - 1)]->"phone")
But for clarity and readability I would break it down a little to -
:global messageStore [/tool sms inbox print as-value]
:global lastMessageIdx ([:len $messageStore] - 1)
:put ([:pick $messageStore $lastMessageIdx]->"phone")
harvey
July 5, 2020, 11:15am
5
Hi, thanks. However, the first line returns the error:
“expected end of command (line 1 column 29):”
harvey
July 5, 2020, 11:17am
6
The SMS inbox is a 2D array, tips on how to work with and get parameter values from arrays can be found in the Scripting Tips and Tricks section of the wiki, specifically sections 5. Get values for properties if ‘get’ command is not available and 6. Always check what value and type command returns provide useful information for this situation.
To answer the original question directly, the quick and dirty one liner for testing in the terminal would be -
:put ([:pick [/tool sms inbox print as-value] ([/tool sms inbox print count-only] - 1)]->"phone")
But for clarity and readability I would break it down a little to -
:global messageStore [/tool sms inbox print as-value]
:global lastMessageIdx ([:len $messageStore] - 1)
:put ([:pick $messageStore $lastMessageIdx]->"phone")
Hi @redmonkey ,
Your solutions looks to work fine, will need to run more tests but looks ideal
Hi, thanks. However, the first line returns the error:
“expected end of command (line 1 column 29):”
Ah, sorry, here is the fix:
:global lastIx (:len [/tool sms inbox] - 1)
Hello i may see your script, plases
Hello, I have an LtAP LTE device, it is configured with two sims of three sims, it only sends sms through slot one, that is, sim one, however I still cannot receive an SMS response from the device with the execution of a created script. How can I tell the device that when you received a text message, it responds to that text?
I have this now until, but i feel lack a thing
:global messageStore [/tool sms inbox print as-value]
:global lastMessageIdx ([:len $messageStore] - 1)
:put ([:pick $messageStore $lastMessageIdx]->“phone”)
/system gps monitor once do={
:set $lat $(“latitude”)
:set $lon $(“longitude”)
}
/tool sms send lte1 message=“ANSWER 1 - Your location is $lat $lon - PRUEBA ONE” phone-number=([:pick $messageStore $lastMessageIdx]->“phone”)
If you may help me, thanks.
I want know how send sms to the device to answer me .