Skip to content

Commit

Permalink
Applescript workaround to fix macOS --background focus issue
Browse files Browse the repository at this point in the history
  • Loading branch information
TheLastProject committed Mar 2, 2018
1 parent 24dcdf7 commit 011f5c0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Inconsistent font sizing
- Improved main screen resizing and logo showing
- Pext passing None as locale to modules in some cases
- --background stealing focus on macOS

### Removed
- Removed manpage
Expand Down
14 changes: 13 additions & 1 deletion pext/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2072,7 +2072,19 @@ def __init__(self, config_retriever: ConfigRetriever, locale_manager: LocaleMana
self.tabs.currentIndexChanged.connect(self._bind_context)

# Show the window if not --background
if not Settings.get('background'):
if platform.system() == 'Darwin' and Settings.get('background'):
# workaround for https://github.com/Pext/Pext/issues/20
# First, we showMinimized to prevent Pext from being unrestorable
self.window.showMinimized()
# Then, we tell macOS to give the focus back to the last app
applescript_command = ['tell application "System Events"',
'tell process "Finder"',
'activate',
'keystroke tab using {command down}',
'end tell',
'end tell']
Popen(['osascript', '-e', '\n'.join(applescript_command)])
elif not Settings.get('background'):
self.show()

if Settings.get('update_check') is None:
Expand Down

0 comments on commit 011f5c0

Please sign in to comment.