octalmage / active-window

Get active window title in Node.js.
160 stars 51 forks source link

Add try-catch for the window title check script on OSX. #10

Closed tarvainen closed 10 months ago

tarvainen commented 7 years ago

This cool script failed and my node application crashed when the windowless Java app was started in the background and automatically got 'focused' on OSX El Capitan 10.11.6. Instead of crashing lets just return empty string as a active window title.

robsonvn commented 7 years ago

Sounds a good solution!

robsonvn commented 7 years ago

Hi @octalmage, could you check it out?

sebszocinski commented 7 years ago

hey @tarvainen i'm experiencing crashes in OSX as well, but can't seem to be able to pinpoint what's causing it. May I ask how you managed to work out what was causing it to crash? Do you know of a way to log osascript crashes?

tarvainen commented 7 years ago

@rockethouse I was actually using the gkm module for listening my keyboard and mouse activity. On mac the java application launched so that it didn't open visible window but still focused that application. Then the active-window kindly responsed me with an error

node_modules/active-window/scripts/mac.scpt:319:324: execution error: System Events got an error: Can’t get window 1 of process "java" whose value of attribute "AXMain" = true. Invalid index. (-1719)

Then just try-catching the script's parts one by one I could find out the main reason causing this issue. When I was trying to get familiar with osascript I just ran the script from the terminal with osascript mac.scpt.

octalmage commented 7 years ago

@robsonvn you're a collaborator now so feel free to approve and merge this!