Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires AutoHotkey v2.0
- #SingleInstance Force
- ; Variable to store the last clipboard content
- lastClipboard := ""
- ; Set up a timer to monitor the clipboard every 500ms
- SetTimer(CheckClipboardAndWindow, 500)
- CheckClipboardAndWindow() {
- global lastClipboard
- ; Get the current clipboard content
- clipboardContent := A_Clipboard
- ; Check if the clipboard content has changed
- if (clipboardContent != lastClipboard) {
- ; Update the last clipboard content
- lastClipboard := clipboardContent
- ; Clean the text (remove spaces, dashes, parentheses, dots)
- CleanText := RegExReplace(clipboardContent, "[\s\-\(\)\.]", "")
- ; Check if it's a phone number (various formats)
- if (IsPhoneNumber(CleanText)) {
- ; Format the phone number for tel
- FormattedNumber := FormatPhoneNumber(CleanText)
- ; Create tel link
- telLink := "tel:" . FormattedNumber
- ; Show notification
- TrayTip("Phone Number Detected", "Opening tel link for: " . FormattedNumber, "Iconi Mute")
- ; Open the tel link
- Run(telLink)
- }
- ; Function to check if text is a phone number
- IsPhoneNumber(Text) {
- ; Remove any remaining non-numeric characters except +
- NumericText := RegExReplace(Text, "[^\d\+]", "")
- ; Check various phone number patterns:
- ; - 10 digits (US format): 1234567890
- ; - 11 digits starting with 1: 11234567890
- ; - International format starting with +: +11234567890, +441234567890, etc.
- if (RegExMatch(NumericText, "^\d{10}$")) ; 10 digits
- return true
- if (RegExMatch(NumericText, "^1\d{10}$")) ; 11 digits starting with 1
- return true
- if (RegExMatch(NumericText, "^\+\d{10,15}$")) ; International format
- return true
- return false
- }
- ; Function to format phone number for tel
- FormatPhoneNumber(Text) {
- ; Remove any non-numeric characters except +
- NumericText := RegExReplace(Text, "[^\d\+]", "")
- ; If it's a 10-digit US number, add +1
- if (RegExMatch(NumericText, "^\d{10}$"))
- return "+1" . NumericText
- ; If it's 11 digits starting with 1, add +
- if (RegExMatch(NumericText, "^1\d{10}$"))
- return "+" . NumericText
- ; If it already starts with +, return as is
- if (RegExMatch(NumericText, "^\+"))
- return NumericText
- ; Default: return with + prefix
- return "+" . NumericText
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment