AppleScript Programming/Advanced Code List/Hide Application
Tools
General
Sister projects
In other projects
Sometimes, your script will need to do something that doesn't have an AppleEvent defined to accomplish the task. In this case, you may be able to script the task anyway by going through the graphical user-interface (GUI), using a technique calledGUI Scripting.
For example, to hide frontmost application, you can do the following:
tellapplication"System Events"tokeystroke"h"usingcommanddown
Then, to hide all background programs:
tellapplication"System Events"tokeystroke"h"using{commanddown,optiondown}
But when you want to hide aspecific application that is at background, it gets more tricky:
tellapplication"System Events"totellprocess"Safari"tosetvisibletofalse
Safari is just an example here.
I use iKey to run this script once Adium is deactivated:
tellapplication"Adium"setvCountertocounteverywindowifvCounter<2thentellapplication"System Events"totellprocess"Adium"tosetvisibletofalseendtell
Shortly explained, it hides Adium if there is only one window (like, buddy-list) open.