dictation-toolbox / dragonfly

Speech recognition framework allowing powerful Python-based scripting and extension of Dragon NaturallySpeaking (DNS), Windows Speech Recognition (WSR), Kaldi and CMU Pocket Sphinx
GNU Lesser General Public License v3.0
375 stars 73 forks source link

Can't always get the title of iTerm window when maximized #369

Open denvaar opened 1 year ago

denvaar commented 1 year ago

I don't think this is necessarily a dragonfly bug, but I wanted to at least mention it here since it might affect people.

I'm not sure if it's an iTerm issue, or something with Applescript itself, but I noticed that sometimes AppContext fails to match the title of the window, because the value was being set to "msng", which means "missing" according to this.

I logged what this gives in both situations where the iTerm window is not full screen vs when it is full screen.

Not full Screen

{'minW': 'msng', 'orie': 'msng', 'posn': [-31, -631], 'axds': 'msng', 'rold': 'standard window', 'focu': False, 'titl': 'app:nvim ext:py mode:n', 'ptsz': [1506, 583], 'help': 'msng', 'ects': [], 'enaB': 'msng', 'maxV': 'msng', 'role': 'AXWindow', 'valL': 'msng', 'sbrl': 'AXStandardWindow', 'selE': 'msng', 'pnam': 'app:nvim ext:py mode:n', 'desc': 'standard window', 'pcls': 'cwin'}

Full Screen (pnam missing)

{'minW': 'msng', 'orie': 'msng', 'posn': [0, 0], 'axds': 'msng', 'rold': 'window', 'focu': False, 'titl': '', 'ptsz': [1728, 37], 'help': 'msng', 'ects': [], 'enaB': 'msng', 'maxV': 'msng', 'role': 'AXWindow', 'valL': 'msng', 'sbrl': 'AXUnknown', 'selE': 'msng', 'pnam': 'msng', 'desc': 'window', 'pcls': 'cwin'}

Next, I tried to use the latest version of py-applescript to see if it made a difference, and it did not.

I also tried to run the Applescript code manually via the editor, and found that it also produced missing values. You can see from these screenshots that there is missing info when the iTerm window is maximized.

image image

I don't know anything about Applescript, but maybe there's a more reliable way to query this kind of information. Or maybe there's just a bug with iTerm. For now I just added a hack that works well enough for my needs.

# windows/darwin_window.py

    def _get_window_text(self):
        title = self.get_properties().get('pnam')

        if title != 'msng':
            return title

        script = '''
tell application "iTerm"
            tell current window
                get name
            end tell
        end tell
        '''
        hack = applescript.AppleScript(script).run()
        return hack

I'm on Monterey 12.5. I have another machine with a previous macOS version and it doesn't happen there.

Thanks

drmfinlay commented 1 year ago

Hello Denver,

Thank you for reporting this problem in detail. The cause appears to be iTerm or macOS itself. I do recall having similar issues with fullscreen macOS windows in the past though. Do you know if it happens with other application windows?

Either way, perhaps a more general version of your workaround should be added to the `_get_window_module' procedure? I'll look into this.