snapshot of https://github.com/ActivityWatch/aw-watcher-window.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Build / test on ubuntu-latest (py-3.9) (push) Failing after 2m36s
Build / typecheck (push) Successful in 1m38s
Build / test on macos-latest (py-3.9) (push) Has been cancelled
Build / test on windows-latest (py-3.9) (push) Has been cancelled
CodeQL / Analyze (python) (push) Failing after 1s
Some checks failed
Build / test on ubuntu-latest (py-3.9) (push) Failing after 2m36s
Build / typecheck (push) Successful in 1m38s
Build / test on macos-latest (py-3.9) (push) Has been cancelled
Build / test on windows-latest (py-3.9) (push) Has been cancelled
CodeQL / Analyze (python) (push) Failing after 1s
This commit is contained in:
65
aw_watcher_window/printAppStatus.jxa
Executable file
65
aw_watcher_window/printAppStatus.jxa
Executable file
@@ -0,0 +1,65 @@
|
||||
#!/usr/bin/osascript -l JavaScript
|
||||
|
||||
// adapted from:
|
||||
// https://gist.github.com/EvanLovely/cb01eafb0d61515c835ecd56f6ac199a
|
||||
|
||||
// new to jxa?
|
||||
// - https://apple-dev.groups.io/g/jxa/wiki/3202
|
||||
// - interactive repl: `osascript -il JavaScript`
|
||||
// - API reference: Script Editor -> File -> Open Dictionary
|
||||
|
||||
var seApp = Application("System Events");
|
||||
var oProcess = seApp.processes.whose({frontmost: true})[0];
|
||||
var appName = oProcess.displayedName();
|
||||
|
||||
// as of 05/01/21 incognio & url are not actively used in AW
|
||||
// variables must be set to `undefined` since this script is re-run via osascript
|
||||
// and the previously set values will be cached otherwise
|
||||
var url = undefined, incognito = undefined, title = undefined;
|
||||
|
||||
// it's not possible to get the URL from firefox
|
||||
// https://stackoverflow.com/questions/17846948/does-firefox-offer-applescript-support-to-get-url-of-windows
|
||||
|
||||
switch(appName) {
|
||||
case "Safari":
|
||||
// incognito is not available via safari applescript
|
||||
url = Application(appName).documents[0].url();
|
||||
title = Application(appName).documents[0].name();
|
||||
break;
|
||||
case "Google Chrome":
|
||||
case "Google Chrome Canary":
|
||||
case "Chromium":
|
||||
case "Brave Browser":
|
||||
const activeWindow = Application(appName).windows[0];
|
||||
const activeTab = activeWindow.activeTab();
|
||||
|
||||
url = activeTab.url();
|
||||
title = activeTab.name();
|
||||
incognito = activeWindow.mode() === 'incognito';
|
||||
break;
|
||||
case "Firefox":
|
||||
case "Firefox Developer Edition":
|
||||
title = Application(appName).windows[0].name();
|
||||
break;
|
||||
default:
|
||||
mainWindow = oProcess.
|
||||
windows().
|
||||
find(w => w.attributes.byName("AXMain").value() === true)
|
||||
|
||||
// in some cases, the primary window of an application may not be found
|
||||
// this occurs rarely and seems to be triggered by switching to a different application
|
||||
if(mainWindow) {
|
||||
title = mainWindow.
|
||||
attributes.
|
||||
byName("AXTitle").
|
||||
value()
|
||||
}
|
||||
}
|
||||
|
||||
// key names must match expected names in lib.py
|
||||
JSON.stringify({
|
||||
app: appName,
|
||||
url,
|
||||
title,
|
||||
incognito
|
||||
});
|
||||
Reference in New Issue
Block a user