MacOS – AppleScript set focus on terminal window

applescriptmacospythonterminal

I have a AppleScript, which changes the position and the size of the application Terminal:

Like here:

tell application "Terminal"
   set position of front window to {1, 1}
   set size of front window to {1, 1}
end tell

When i'm setting the size of the window to {1, 1}, it becomes really small that it's not more visible.

My question is how can i set the focus of the window for a specific time, that neither any user activity nor any application can catch the focus of the terminal window?

Best way would be with AppleScript, but any programmatically solution with python would be nice.

Best Answer

activate application "Terminal"
tell application "Terminal"
   set position of front window to {1, 1}
   set size of front window to {1, 1}
end tell
tell application "System Events" to keystroke "your message here\rexit\r"

Additionally you can get help from AppleScript get active Application

to put focus back on original application