Shortcuts: Extract Contact's Mobile Phone Number

Recently there was a query on the Automators podcast forum, where someone wanted to know how to retrieve a mobile phone number from a contact using Shortcuts. This isn’t something that Shortcuts supports “out-of-the-box”, but it is something that Shortcuts can do with a bit of cajoling. In this post I’ll explain some of the details about one way of doing it.

The approach I used was actually based on a Workflow solution I came up with several years back for someone wanting to do the same sort of thing, but with a contact’s physical address. The underlying principle is to convert the exported contact details to a vCard format. vCard supports more specific properties than Shortcuts does alone, and it is a plain text file format. Therefore, by converting the contact details to a vCard, we can carry out a text match to find the mobile phone number.

The shortcut begins by having the user select a contact. The contact is saved as a vCard (VCF) file to iCloud and then read back in. At this point, we can set the name of the file to convert the vCard file to a .TXT file internally and delete the original file. At this point we have no files remaining, but we do have the content of the vCard file available as text in the shortcut.

The shortcut then finds the lines of content containing cellphone (mobile phone) entries. If no entries are found, some final text is revealed to the user via a Show Result action. If one or more matches is found, the trimmed lines will be put into some final text and revealed in the same way. The results therefore are of the following format.

Example: No Match

John Smith
No mobile number found.

Example: Match

Jane Doe
07555123456

Finally, after the user has been informed, the text is also set as the final output. This is to show how the example could be used to feed the result into another shortcut.

Below you can download the shortcut and also review the content in the extended screenshot. Just keep in mind that while Shortcuts, and in particular it’s content graph, are very powerful, there are some rough edges and often, with a bit of insight and persistence you can find a way around the limitations.

Author: Stephen Millard
Tags: | shortcuts |

Buy me a coffeeBuy me a coffee



Related posts that you may also like to read