From e336c0712872cadcb4f53c2da03f4f89cee89527 Mon Sep 17 00:00:00 2001 From: Michael Peterson Date: Fri, 17 Aug 2018 13:10:40 -0400 Subject: [PATCH] Fix the osacript to work with versioned names of python (e.g. 'python3.7') --- blessclient/tokengui.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/blessclient/tokengui.py b/blessclient/tokengui.py index caaa83f..5728986 100644 --- a/blessclient/tokengui.py +++ b/blessclient/tokengui.py @@ -1,6 +1,7 @@ from __future__ import absolute_import import platform import os +import subprocess from six.moves.tkinter import Tk, Label, Entry, Button, ACTIVE, W, mainloop @@ -35,7 +36,10 @@ def doGUI(self, hostname=None): if platform.system() == 'Darwin': # Hack to get the GUI dialog focused in OSX - os.system('/usr/bin/osascript -e \'tell app "Finder" to set frontmost of process "python" to true\'') + # https://stackoverflow.com/questions/1892339/how-to-make-a-tkinter-window-jump-to-the-front/37235492#37235492 + tmpl = 'tell application "System Events" to set frontmost of every process whose unix id is {} to true' + script = tmpl.format(os.getpid()) + subprocess.check_call(['/usr/bin/osascript', '-e', script]) mainloop()