To activate the telegram.exe

156 Views Asked by At

Hello I have problems in running the code below:

import pywinauto,time
from pywinauto.application import Application
from pywinauto.keyboard import send_keys

app = Application().start(cmd_line= "C:\Users\User\AppData\Roaming\Telegram Desktop\Telegram.exe" )

time.sleep(1)

------------------------------------------------------------------------
File "c:\Users\User\Desktop\Python\project", line 5
    app = Application().start(cmd_line= "C:\Users\User\AppData\Roaming\Telegram Desktop\Telegram.exe" )
                                                                                                      ^

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape
PS C:\Users\User\Desktop\Python>

please help me, thank you very much

I want to write code to activate telegram.exe on window 10 desktop

1

There are 1 best solutions below

0
Vasily Ryabov On

It's a simple basic Python error. You need raw string: app = Application().start(cmd_line=r"C:\Users\User\AppData\Roaming\Telegram Desktop\Telegram.exe") because \r and \t are special escape sequences: \R is a new line caret return symbol, \T is a tabulation one.

P.S. General advise about Telegram automation: please use Python API client instead of GUI automation. It is much more reliable way. Also Telegram desktop window doesn't provide many automation capabilities. It seems by design.