To use the library, you must first call ActiveWindow.initialize(). On MacOS, if you are not running a GUI application, you should pass { osxRunLoop: true } to initialize() to enable subscriptions.
On MacOS, you must also check requestPermissions() to ensure the application has screen recording permissions; otherwise, the window title will return as an empty string.
import ActiveWindow from '@paymoapp/active-window';
// Must be called before any other method
ActiveWindow.initialize();
// Required for MacOS to fetch window titles
if (!ActiveWindow.requestPermissions()) {
console.log('Error: You need to grant screen recording permission in System Preferences > Security & Privacy > Privacy > Screen Recording');
process.exit(0);
}
const activeWin = ActiveWindow.getActiveWindow();
console.log('Window title:', activeWin.title);
console.log('Application:', activeWin.application);
console.log('Application path:', activeWin.path);
console.log('Application PID:', activeWin.pid);
console.log('Application icon:', activeWin.icon);
import ActiveWindow from '@paymoapp/active-window';
ActiveWindow.initialize();
if (!ActiveWindow.requestPermissions()) {
console.log('Error: You need to grant screen recording permission in System Preferences > Security & Privacy > Privacy > Screen Recording');
process.exit(0);
}
const activeWin = ActiveWindow.getActiveWindow();
console.log('Window title:', activeWin.title);
console.log('Application:', activeWin.application);
console.log('Application path:', activeWin.path);
console.log('Application PID:', activeWin.pid);
console.log('Application icon:', activeWin.icon);