#!python # -*- mode: python; Encoding: utf-8; coding: utf-8 -*- # Last updated: <2022/04/24 05:35:31 +0900> """ Appli window activate. copy and paste. 1. Activate the Adobe Acrobat Reader DC window and send Ctrl+C. 2. Replace CRLF in clipboard with space. 3. Activate the DeepL Desktop window and send Ctrl+A, Delete, Ctrl+V Windows10 x64 21H2 + Python 3.9.12 64bit + PyAutoGUI 0.9.53 + PyGetWindow 0.0.9 """ import pyautogui as ag import pygetwindow as gw import pyperclip import sys import time pdfviewer = "Reader DC" deepl = "DeepL " def activate_window(w): """Activate appli window.""" try: w.activate() except Exception: w.minimize() w.restore() time.sleep(0.35) def get_window(name): hwnds = gw.getWindowsWithTitle(name) w = None if hwnds != []: w = hwnds[0] else: print("Error: Not found %s" % name) return w def main(): w = get_window(pdfviewer) if w is None: sys.exit() activate_window(w) ag.hotkey("ctrl", "c") time.sleep(0.25) # replace CRLF to space txt = pyperclip.paste() newtxt = " ".join(txt.splitlines()) # newtxt = txt.replace("\n", " ") pyperclip.copy(newtxt) # print(newtxt) w = get_window(deepl) if w is None: sys.exit() activate_window(w) ag.hotkey("ctrl", "a") time.sleep(0.25) ag.hotkey("delete") time.sleep(0.25) ag.hotkey("ctrl", "v") time.sleep(0.25) if __name__ == '__main__': main()