Amend Variable beginning and check an if

Hi,

I have a variable named ‘Mobile Number’ I want to setup an if statement. if KM variable starts with the number ‘7’ then add a ‘0’ to the beginning of the variable to make it ‘07…’

i am having difficulty doing this…

can anyone assist?

Thanks

Hey Ali,

--Alain

1 Like

@alain’s solution is very good, a probably the best way to do it.

You can also do exactly what you said by using the If Then Else action and a Set Variable to Text action.

1 Like

Thank you both very much.

Hey Ali,

Just to add some variety let’s do that with AppleScript.

-Chris

------------------------------------------------------------
# Requires Keyboard Maestro 7.0.2 or later.
------------------------------------------------------------
tell application "Keyboard Maestro Engine"
  tell variable "Mobile Number"
    if it exists then
      set myMobileNumber to its value
      if myMobileNumber starts with "7" then
        set myMobileNumber to "0" & myMobileNumber
      end if
    end if
  end tell
end tell
------------------------------------------------------------
1 Like