KraKaKaa

Removing Leading and Trailing White Spaces and Empty Characters AHK Script ( AutoHotKey Script)

Oct 21st, 2023 (edited)
1,679
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Autohotkey 1.06 KB | Source Code | 0 0
  1. ; AutoHotKey Script to Trim White Spaces from Clipboard
  2.  
  3. #Persistent  ; Keep the script running
  4. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases
  5. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability
  6. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory
  7.  
  8. ; Hotkey: Ctrl + Shift + T
  9. ^+T::
  10.     ; Backup the original clipboard content
  11.     originalClipboard := ClipboardAll
  12.    
  13.     ; Wait for the clipboard to contain text
  14.     ClipWait, 1
  15.    
  16.     ; Trim leading and trailing white spaces using RegEx
  17.     Clipboard := RegExReplace(Clipboard, "^\s+|\s+$", "")
  18.    
  19.     ; Wait a moment for the clipboard content to be updated
  20.     Sleep, 100
  21.    
  22.     ; Restore the original clipboard content if it was non-text
  23.     if (Clipboard != originalClipboard) {
  24.         Clipboard := originalClipboard
  25.     }
  26.    
  27.     ; Notify the user
  28.     ToolTip, Clipboard trimmed!
  29.     SetTimer, RemoveToolTip, -2000  ; Show the tooltip for 2 seconds
  30. return
  31.  
  32. RemoveToolTip:
  33.    ToolTip
  34. return
  35.  
Advertisement