|
|
@Zett activate will bring the app to the front whether it is open or not. So really, all you need to do is check if the app you're looking for is frontmost. If it is, you hide it. If it isn't, you activate it. Ideally this should work but I don't care enough anymore to test it.
set appName to "Mail"
set needsActivation to false
tell application "System Events"
if frontmost of process appName then
set visible of process appName to false
else
set needsActivation to true
end if
end tell
if needsActivation then
tell application appName to activate
end if
Source: https://my.remarkbox.com/2fc4f7e6-4208-11e9-9d31-040140774501
Snapshot: 2026-04-27T03:23:44Z
Generator: Remarkbox 97a1fff