问题
I am new to sikuli , Is there a way to find whether the Microsoft Outlook is already opened ? If its opened make it as a active window else open Outlook .
Below is the code which i tried , Some times the Maximize() will work correctly. Otherwise it will open outlook even if it already exists
OutlookOpen()
def OutlookOpen():
if exists("1424161703182.png"):
Maximize()
else:
openO()
def Maximize():
switchApp("Microsoft Outlook")
wait(1)
type(" ", KEY_ALT)
type("x")
print("Maximized")
def openO():
OpenApp(r'C:\Program Files (x86)\Microsoft Office\Office14\outlook.exe')
wait(2)
print("opened")
回答1:
What you could do is look if outlook exists (grab something unique, pictures are most easy). If is doesn't exist look if outlook exists on the minimized bar (picture is mostly a little different, and sikuli is sensitive).
For example:
Image_TB_Open = ("image1")
Image_TB_Minimized = ("image2")
class ThunderBird():
def __init__(self):
self.TBird()
def TBird(self):
if exists(Image_TB_Open):
print('ThunderBird is open!')
elif exists(Image_TB_Minimized):
print('ThunderBird is open but minimized!')
else:
print('ThunderBird is closed!')
# Run class
ThunderBird()
Edit:
Okey, I made a far more simple solution.
Might as well share it here.
I made a definition to do the work for me.
# vcProgram = Program name.
def programActive(self, vcProgram):
self.vcProgram = vcProgram
searchResult = App.focus(vcProgram)
if (vcProgram in str(searchResult)):
return 'True'
else:
return 'False'
To call this definition I use:
fActive = self.programActive('Firefox')
If fActive
is True
then the program is already open.
来源:https://stackoverflow.com/questions/28559997/check-if-window-is-already-exist-then-make-the-window-as-active-else-open