res=$(osascript -e 'tell"tell application "System\"System Events"Events\" to get name of application processes whose frontmost is true and visible is true'true");
if [ $res == "Kim" ]
then
osascript -e 'tell"tell application "System\"System Events"Events\" to set visible of process "Kim"\"Kim\" to false'"false"
else
open -a 'Kim.app'
fi
I did it like this, it works but excutes very slow, how to optimize this?