У меня есть AppleScript, который изменяет положение и размер терминала приложения:
Как здесь:
tell application "Terminal"
set position of front window to {1, 1}
set size of front window to {1, 1}
end tell
Когда я устанавливаю размер окна на {1, 1}
, оно становится очень маленьким, чтобы его не было видно.
Мой вопрос: как я могу установить фокус окна на определенное время, чтобы ни пользовательская активность, ни какое-либо приложение не могли перехватить фокус окна терминала?
Лучше всего было бы с AppleScript, но любое программное решение с python было бы неплохо.
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"
Кроме того, вы можете получить помощь от AppleScript получить активное приложение
вернуть фокус на исходное приложение
С помощью javadevg и ответа AppleScript получить активное приложение я создал следующее решение:
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
Я мало работаю с AppleScript, поэтому извините за мой стиль кодирования и т. д.
С помощью этого скрипта откроется терминал, и он не потеряет фокус, пока терминал не закроется.
Йозеф Легени
Они1
пользователь14492
Они1
Стэн Хатчеон