annotate collector/current_window_title_osx.py @ 10:6b6b1ea0e00d default tip

ok for no window to be focused (untested)
author drewp@bigasterisk.com
date Mon, 13 Mar 2023 19:16:58 -0700
parents 5ad799e534a5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
1 from osascript import osascript
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
2 #https://stackoverflow.com/questions/5292204/macosx-get-foremost-window-title
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
3
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
4
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
5 def get_current_window_title():
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
6 _, title, _ = osascript('''
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
7 tell application "System Events"
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
8 set frontApp to name of first application process whose frontmost is true
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
9 end tell
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
10
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
11 tell application frontApp
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
12 set window_name to name of front window
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
13 end tell
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
14 ''')
3d7fc94a404a a few more inputs; daemonize
drewp@bigasterisk.com
parents:
diff changeset
15 return title