From 43eef1dcd89b5e2c54d2a0f5eac905bc597cddeb Mon Sep 17 00:00:00 2001 From: kikuyan Date: Wed, 30 Jun 2021 15:18:44 +0900 Subject: [PATCH] avoid phantom windows in osascript --- youtube_dl/YoutubeDL.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/youtube_dl/YoutubeDL.py b/youtube_dl/YoutubeDL.py index cf15c47ea..7184f89e3 100755 --- a/youtube_dl/YoutubeDL.py +++ b/youtube_dl/YoutubeDL.py @@ -557,7 +557,18 @@ class YoutubeDL(object): window_title = None try: ttyname = os.ttyname(self._screen_file.fileno()) - opts = ['-e', 'tell app "Terminal" to get custom title of item 1 of (every window whose tty is "%s")' % ttyname] + scpt = [ + 'tell app "Terminal"', + 'repeat with win in (every window)', + 'if tty of win is "%s" then' % ttyname, + 'return custom title of win', + 'end if', + 'end repeat', + 'end tell' + ] + opts = [] + for s in scpt: + opts += ['-e', s] cmd = ([encodeFilename('osascript', True)] + [encodeArgument(o) for o in opts]) p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)