MacOSX: Pobierz tytuł okna

Używam tego kodu, aby uzyskać tytuł okna:

tell application "System Events"
    set frontApp to name of first application process whose frontmost is true
end tell

tell application frontApp
    set window_name to name of front window
end tell

Jednak w niektórych przypadkach nie udaje się to. Oczywiście zawodzi, gdy nie ma otwartego okna, ale to jest Ok. Jednak w niektórych przypadkach, na przykład dla Texmaker, Błąd ten nie występuje. Nie działa również w przypadku podglądu.

Jaki byłby sposób na uzyskanie tytułu okna, nawet w przypadku takich przypadków jak Texmaker?

Author: Albert, 2011-03-13

3 answers

To chyba działa Zawsze:

global frontApp, frontAppName, windowTitle

set windowTitle to ""
tell application "System Events"
    set frontApp to first application process whose frontmost is true
    set frontAppName to name of frontApp
    tell process frontAppName
        tell (1st window whose value of attribute "AXMain" is true)
            set windowTitle to value of attribute "AXTitle"
        end tell
    end tell
end tell

return {frontAppName, windowTitle}

Mam pomysł z tutaj .

 18
Author: Albert,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-03-14 01:10:18

Bazując na odpowiedzi Alberta, zamiast tego zrobiłbym

global frontApp, frontAppName, windowTitle

set windowTitle to ""
tell application "System Events"
    set frontApp to first application process whose frontmost is true
    set frontAppName to name of frontApp
    set windowTitle to "no window"
    tell process frontAppName
        if exists (1st window whose value of attribute "AXMain" is true) then
            tell (1st window whose value of attribute "AXMain" is true)
                set windowTitle to value of attribute "AXTitle"
            end tell
        end if
    end tell
end tell

return {frontAppName, windowTitle}

To jest hack i nie mam doświadczenia, ale zaletą jest to, że nie zawiesza się, jeśli nie ma okna.

 4
Author: user2330514,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2016-11-01 23:32:29

Wypróbuj następujący skrypt:

tell application "System Events"
    set window_name to name of first window of (first application process whose frontmost is true)
end tell

Nie zweryfikowałem jednak, czy działa to dla TextMaker.

 2
Author: sakra,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2011-03-13 21:07:50