Skip to content

Commit

Permalink
macOS (Apple Script version): fixed activate() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalmat committed Mar 9, 2022
1 parent a6340cc commit 1a1aaaa
Showing 1 changed file with 11 additions and 14 deletions.
25 changes: 11 additions & 14 deletions src/pywinctl/_pywinctl_macos.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,7 +515,7 @@ def show(self, wait: bool = False) -> bool:
while wait and retries < WAIT_ATTEMPTS and not self.visible:
retries += 1
time.sleep(WAIT_DELAY * retries)
return self.visible
return self.visible and self.isActive

def hide(self, wait: bool = False) -> bool:
"""
Expand All @@ -529,7 +529,7 @@ def hide(self, wait: bool = False) -> bool:
set winName to arg2 as string
set isPossible to false
try
tell application "System Events" to tell application "%s""
tell application "System Events" to tell application "%s"
set isPossible to exists visible of window winName
if isPossible then
tell window winName to set visible to false
Expand Down Expand Up @@ -558,18 +558,17 @@ def activate(self, wait: bool = False) -> bool:
:param wait: set to ''True'' to wait until action is confirmed (in a reasonable time lap)
:return: ''True'' if window activated
"""
# self._app.activateWithOptions_(NSApplicationActivateIgnoringOtherApps)
if not self.isVisible:
self.show(wait=wait)
if self.isMinimized or self.isMaximized:
self.restore(wait=wait)
self._app.activateWithOptions_(Quartz.NSApplicationActivateIgnoringOtherApps)
cmd = """on run {arg1, arg2}
set appName to arg1 as string
set winName to arg2 as string
try
tell application "System Events" to tell application process appName
set visible to true
activate
tell window winName to set visible to true
tell window winName to set index to 1
end tell
end try
tell application "System Events" to tell application process appName
tell window winName to set value of attribute "AXMain" to true
end tell
end run"""
proc = subprocess.Popen(['osascript', '-', self._appName, self.title],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, encoding='utf8')
Expand Down Expand Up @@ -1183,14 +1182,12 @@ def subfillit(subNameList, subSizeList, subPosList, subAttrList, section="", lev
for j in subPath:
if len(submenu) > j:
submenu = submenu[j]
if not submenu:
break
subPos = subPos[j]
subSize = subSize[j]
subAttr = subAttr[j] if addItemInfo else []
else:
break
if submenu and len(submenu) > 0:
if submenu:
option[name]["hSubMenu"] = self._getNewHSubMenu(ref)
option[name]["entries"] = {}
subfillit(submenu, subSize, subPos, subAttr,
Expand Down

0 comments on commit 1a1aaaa

Please sign in to comment.