2

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.

  • Could you precise what would be a typical use case of what you are asking for? From your question it is not clear what you are trying to achieve. – Jozef Legény Jun 9 '16 at 9:42
  • I'm developing with a Teensy board, where the Terminal will open and self-typing some commands in the terminal window. I want that NO user-action is possible during the terminal window is open, nor keyboard either mouse action. – Oni1 Jun 9 '16 at 9:47
  • You could just tell the users to not to type/do anything.? – user14492 Jun 11 '16 at 22:35
  • That's not possible, every user-action should be ignored during the terminal is opened and focused. – Oni1 Jun 12 '16 at 23:46
  • Is there any reason you cannot use a shell script to achieve this? It seems unnecessary to use UI scripting to run commands via terminal – Stan Hutcheon Jun 13 '16 at 12:11
1
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

  • Your answer is not correct, but your hint to the question AppleScript get active Application helped me a lot! – Oni1 Jun 16 '16 at 9:50
  • "Your answer is not correct," doesn't help the community. Pls share details and if you think there's better solution share that too.. – javadevg Jun 16 '16 at 17:06
  • Look at my answer – Oni1 Jun 17 '16 at 11:35
0

With the help of javadevg and the answer of AppleScript get active Application, i created the following solution:

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

tell application "System Events"
  set frontmostProcess to first process where it is frontmost
  set visible of frontmostProcess to false
  repeat while (frontmostProcess is frontmost)
    delay 0.1
  end repeat
  set secondFrontmost to name of first process where it is frontmost
  set frontmost of frontmostProcess to true
end tell

tell application "System Events"
  set activeApp to name of first application process whose frontmost is true
  repeat while (get name of every application process) contains "Terminal"
    try
        activate application "Terminal"
    end try
  end repeat
end tell

I'm not working a lot with AppleScript, so please excuse my coding-style etc.

With this script a Terminal will open, and it doesn't loose the focus until the terminal will close.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .