File: ec.pyw
   1 #!/usr/bin/python3
   2 
   3 # The MIT License (MIT)
   4 #
   5 # Copyright © 2024 pacman64
   6 #
   7 # Permission is hereby granted, free of charge, to any person obtaining a copy
   8 # of this software and associated documentation files (the “Software”), to deal
   9 # in the Software without restriction, including without limitation the rights
  10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11 # copies of the Software, and to permit persons to whom the Software is
  12 # furnished to do so, subject to the following conditions:
  13 #
  14 # The above copyright notice and this permission notice shall be included in
  15 # all copies or substantial portions of the Software.
  16 #
  17 # THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  23 # SOFTWARE.
  24 
  25 
  26 # ec
  27 #
  28 # Empty Clipboard empties the text clipboard, true to its name. This script
  29 # only works on Windows.
  30 
  31 
  32 from sys import argv, exit, stderr
  33 
  34 
  35 info = '''
  36 ec
  37 
  38 Empty Clipboard empties the text clipboard, true to its name. This script
  39 only works on Windows.
  40 '''.strip()
  41 
  42 # a leading help-option arg means show the help message and quit
  43 if len(argv) > 1 and argv[1].lower() in ('-h', '--h', '-help', '--help'):
  44     print(info, file=stderr)
  45     exit(0)
  46 
  47 
  48 try:
  49     from ctypes import windll
  50 except:
  51     print('this script only works on windows', file=stderr)
  52     exit(1)
  53 
  54 try:
  55     u = windll.user32
  56     u.OpenClipboard(None)
  57     u.EmptyClipboard()
  58     u.CloseClipboard()
  59 except:
  60     print('failed to empty the text clipboard', file=stderr)
  61     exit(1)