From 761b23785527b8fbb5d4bca96a830d4fce4876b8 Mon Sep 17 00:00:00 2001 From: Maigo Erit Date: Sun, 8 Jan 2017 15:27:00 +0200 Subject: [PATCH] =?UTF-8?q?try=20to=20fix=20error:=20Can=E2=80=99t=20get?= =?UTF-8?q?=20window=201=20of=20process=20.=20Invalid=20index?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/get-foreground-window-title.osa | 18 ++++++++++-------- app/testscript.sh | 7 +++++++ 2 files changed, 17 insertions(+), 8 deletions(-) create mode 100644 app/testscript.sh diff --git a/app/get-foreground-window-title.osa b/app/get-foreground-window-title.osa index ac74dd3d..49d1fe57 100755 --- a/app/get-foreground-window-title.osa +++ b/app/get-foreground-window-title.osa @@ -1,13 +1,15 @@ global frontApp, frontAppName, windowTitle - set windowTitle to "" + 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 - set windowTitle to title of 1st window - end tell + 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, frontApp} \ No newline at end of file diff --git a/app/testscript.sh b/app/testscript.sh new file mode 100644 index 00000000..9e0e99b4 --- /dev/null +++ b/app/testscript.sh @@ -0,0 +1,7 @@ +#!/bin/bash +for i in `seq 1 5`; + do + echo $i + echo `osascript get-foreground-window-title.osa` + sleep 1 +done \ No newline at end of file