Update to Get Name from Number
I wrote up a description of the Get Nickname From Number Task on Tasker. I ran into a situation today that prompted a small update to this task. Everything was working fine until I got a text from someone that included the leading "1" (US number) in the phone number. That didn't match a person in my contacts, so it read the full phone number.
After doing some playing around, it turns out that it didn't take much to get this to read properly. If the phone number is 10 digits, then go ahead and use the number. If it's 11 digits, then take the last 10 and use that as the number. Unfortunately, Tasker doesn't have any "string length" function. But since I'm working with digits, I can check to see if it's bigger than 999-999-9999 (actually, 9,999,999,999).
The "Variable Section" function will take the last 10 digits of the phone number (characters 2 through 11) if there's a leading 1 on the phone number.
Here's the updated task.
Get Nickname From Number (28)
A1: Variable Set [ Name:%phoneno To:%par1 Do Maths:Off Append:Off ]
A2: Variable Section [ Name:%phoneno From:2 Length:10 Adapt To Fit:Off Store Result In: ] If [ %phoneno > 10000000000 ]
A3: AutoContacts [ Configuration:Name as Nickname: true
Phone Number: %phoneno Package:com.joaomgcd.autocontacts Name:AutoContacts Timeout (Seconds):1000 ]
A4: Return [ Value:%acnickname Stop:On ] If [ %acnickname Set ]
A5: Return [ Value:%par1 Stop:On ] If [ %acnickname !Set ]
After doing some playing around, it turns out that it didn't take much to get this to read properly. If the phone number is 10 digits, then go ahead and use the number. If it's 11 digits, then take the last 10 and use that as the number. Unfortunately, Tasker doesn't have any "string length" function. But since I'm working with digits, I can check to see if it's bigger than 999-999-9999 (actually, 9,999,999,999).
The "Variable Section" function will take the last 10 digits of the phone number (characters 2 through 11) if there's a leading 1 on the phone number.
Here's the updated task.
Get Nickname From Number (28)
A1: Variable Set [ Name:%phoneno To:%par1 Do Maths:Off Append:Off ]
A2: Variable Section [ Name:%phoneno From:2 Length:10 Adapt To Fit:Off Store Result In: ] If [ %phoneno > 10000000000 ]
A3: AutoContacts [ Configuration:Name as Nickname: true
Phone Number: %phoneno Package:com.joaomgcd.autocontacts Name:AutoContacts Timeout (Seconds):1000 ]
A4: Return [ Value:%acnickname Stop:On ] If [ %acnickname Set ]
A5: Return [ Value:%par1 Stop:On ] If [ %acnickname !Set ]
Comments
Post a Comment