Automator keeps using numbers in exponential form

Solution 1:

A simple and fast way requires to install a scripting edition Satimage.osax (direct d/l) and works with regex. The certificate of the pkg sadly expired!

on run {input, parameters}
    set text1 to change "^0+" into "" in (the clipboard as string) with regexp
    do shell script "open https://api.whatsapp.com/send?phone=971" & text1
    return input
end run

^0+ strips off leading zeros!


A second one with sed but no additional installs:

on run {input, parameters}
    set text1 to do shell script "echo " & quoted form of (the clipboard as string) & " | sed 's/^0*//'"
    do shell script "open https://api.whatsapp.com/send?phone=971" & text1
    return input
end run
  • quoted form of (the clipboard as string): '0501234567'
  • do shell script "echo " & '0501234567' & " | sed 's/^0*//'": run shell command echo '0501234567' | sed 's/^0*//' in an Apple script
  • echo '0501234567' | sed 's/^0*//': send the output of echo to the stream editor sed and do something with it
  • ^0*: regular expression: ^ = start of line * = quantifier- matches between zero and unlimited times, as many times as possible
  • 's/^0*//': 's/reg_ex/replacement/': substitute the replacement string for the first instance of the regular expression in the pattern space. This means: replace as many leading zeros as possible with the replacement string (=NIL/nothing) = strip off leading zeros
  • set text1 to ...: $text1=501234567
  • do shell script "open https://api.whatsapp.com/send?phone=971" & text1: open https://api.whatsapp.com/send?phone=971501234567

Both tested in 10.11.6 (El Capitan) only.

Solution 2:

Looking at your example 0501234567 and your expected output 971501234567, then I'm assuming all you are really trying to do is strip the first character from 0501234567, of what's on the clipboard, and append 501234567 to the URL https://api.whatsapp.com/send?phone=971 so that you have https://api.whatsapp.com/send?phone=971501234567 as the URL for use with the open command in the do shell script command.

If I'm understanding your need correctly, then simply this is all you need:

do shell script ¬
    "open https://api.whatsapp.com/send?phone=971" & ¬
    text 2 thru -1 of (the clipboard as text)
  • Note that the use of the line continuation character ¬ is not necessary, I'm just using it so the whole command line shows without having to scroll.

The phone number e.g. 0501234567 on the clipboard after all is not a real number in the sense of an integer that mathematical calculations need to be performed on it, in this use case. It is simply a text string of numeric characters for the manner in which it needs to be used and should be expressly treated as such.