johnlindquist / kit

Script Kit. Automate Anything.
https://scriptkit.com
MIT License
3.91k stars 138 forks source link

"Focus Window" script doesn't work #1426

Open alexilyaev opened 10 months ago

alexilyaev commented 10 months ago

Running "Focus Window" script does not show anything in the list. Debugging the script it seems that w.name !== "" is always false on my machine.

Here's an example logging all windows:

[2024-01-16 15:23:10.488] [info]  Found mac-windows in /Users/alex/.kenv/package.json
[2024-01-16 15:23:10.588] [info]  {"height":1415,"name":"","number":20923,"ownerName":"Code","pid":39825,"width":2560,"x":0,"y":25}
[2024-01-16 15:23:10.588] [info]  {"height":500,"name":"","number":19675,"ownerName":"Open and Save Panel Service","pid":42256,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.588] [info]  {"height":500,"name":"","number":18734,"ownerName":"Emoji & Symbols","pid":39747,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.588] [info]  {"height":1415,"name":"","number":17988,"ownerName":"Google Chrome","pid":32027,"width":2560,"x":0,"y":25}
[2024-01-16 15:23:10.588] [info]  {"height":500,"name":"","number":15931,"ownerName":"Control Center","pid":651,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.588] [info]  {"height":100,"name":"","number":13743,"ownerName":"Dropbox","pid":79962,"width":100,"x":0,"y":1340}
[2024-01-16 15:23:10.588] [info]  {"height":50,"name":"","number":13742,"ownerName":"Dropbox","pid":79962,"width":50,"x":0,"y":1390}
[2024-01-16 15:23:10.589] [info]  {"height":380,"name":"","number":13741,"ownerName":"Dropbox","pid":79962,"width":360,"x":1100,"y":530}
[2024-01-16 15:23:10.589] [info]  {"height":1079,"name":"","number":8735,"ownerName":"Sourcetree","pid":649,"width":1728,"x":416,"y":193}
[2024-01-16 15:23:10.589] [info]  {"height":1415,"name":"","number":8668,"ownerName":"Code","pid":39825,"width":2560,"x":0,"y":25}
[2024-01-16 15:23:10.589] [info]  {"height":1415,"name":"","number":8667,"ownerName":"Code","pid":39825,"width":2560,"x":0,"y":25}
[2024-01-16 15:23:10.589] [info]  {"height":500,"name":"","number":8632,"ownerName":"CursorUIViewService","pid":829,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.589] [info]  {"height":500,"name":"","number":8783,"ownerName":"CursorUIViewService","pid":829,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.589] [info]  {"height":500,"name":"","number":20073,"ownerName":"CursorUIViewService","pid":829,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.589] [info]  {"height":500,"name":"","number":19847,"ownerName":"CursorUIViewService","pid":829,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.589] [info]  {"height":600,"name":"","number":13740,"ownerName":"Dropbox","pid":79962,"width":400,"x":0,"y":840}
[2024-01-16 15:23:10.589] [info]  {"height":500,"name":"","number":8613,"ownerName":"Open and Save Panel Service","pid":39738,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.589] [info]  {"height":180,"name":"","number":3664,"ownerName":"Kit","pid":7007,"width":240,"x":2080,"y":25}
[2024-01-16 15:23:10.589] [info]  {"height":500,"name":"","number":713,"ownerName":"loginwindow","pid":396,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.589] [info]  {"height":500,"name":"","number":180,"ownerName":"iTerm2","pid":2485,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.589] [info]  {"height":1415,"name":"","number":179,"ownerName":"iTerm2","pid":2485,"width":2560,"x":0,"y":25}
[2024-01-16 15:23:10.589] [info]  {"height":432,"name":"","number":106,"ownerName":"Alfred","pid":996,"width":718,"x":921,"y":214}
[2024-01-16 15:23:10.589] [info]  {"height":52,"name":"","number":101,"ownerName":"Karabiner-NotificationWindow","pid":1435,"width":398,"x":2150,"y":1378}
[2024-01-16 15:23:10.589] [info]  {"height":416,"name":"","number":97,"ownerName":"Google Drive","pid":1059,"width":350,"x":0,"y":1024}
[2024-01-16 15:23:10.589] [info]  {"height":1415,"name":"","number":94,"ownerName":"Sourcetree","pid":649,"width":2560,"x":0,"y":25}
[2024-01-16 15:23:10.590] [info]  {"height":160,"name":"","number":93,"ownerName":"TextInputSwitcher","pid":908,"width":247,"x":1156,"y":653}
[2024-01-16 15:23:10.590] [info]  {"height":500,"name":"","number":89,"ownerName":"Sourcetree","pid":649,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.590] [info]  {"height":128,"name":"","number":83,"ownerName":"Alfred","pid":996,"width":100,"x":100,"y":1212}
[2024-01-16 15:23:10.590] [info]  {"height":1415,"name":"","number":8737,"ownerName":"Sourcetree","pid":649,"width":2560,"x":0,"y":25}
[2024-01-16 15:23:10.590] [info]  {"height":500,"name":"","number":1644,"ownerName":"Kit","pid":7007,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.590] [info]  {"height":480,"name":"","number":1640,"ownerName":"Kit","pid":7007,"width":768,"x":896,"y":202}
[2024-01-16 15:23:10.590] [info]  {"height":1415,"name":"","number":64,"ownerName":"WhatsApp","pid":644,"width":2560,"x":0,"y":25}
[2024-01-16 15:23:10.590] [info]  {"height":500,"name":"","number":22117,"ownerName":"CursorUIViewService","pid":829,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.590] [info]  {"height":1415,"name":"","number":47,"ownerName":"Finder","pid":654,"width":2560,"x":0,"y":25}
[2024-01-16 15:23:10.590] [info]  {"height":570,"name":"","number":2015,"ownerName":"Notion","pid":7926,"width":755,"x":903,"y":379}
[2024-01-16 15:23:10.590] [info]  {"height":1415,"name":"","number":2014,"ownerName":"Notion","pid":7926,"width":2560,"x":0,"y":25}
[2024-01-16 15:23:10.590] [info]  {"height":1440,"name":"","number":35,"ownerName":"AXVisualSupportAgent","pid":606,"width":2560,"x":0,"y":0}
[2024-01-16 15:23:10.593] [info]  {"height":1440,"name":"","number":31,"ownerName":"Notification Center","pid":636,"width":2560,"x":0,"y":0}
[2024-01-16 15:23:10.593] [info]  {"height":500,"name":"","number":22487,"ownerName":"CursorUIViewService","pid":829,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.593] [info]  {"height":1440,"name":"","number":29,"ownerName":"AXVisualSupportAgent","pid":606,"width":2560,"x":0,"y":0}
[2024-01-16 15:23:10.593] [info]  {"height":500,"name":"","number":22486,"ownerName":"CursorUIViewService","pid":829,"width":500,"x":0,"y":940}
[2024-01-16 15:23:10.593] [info]  {"height":1440,"name":"","number":28,"ownerName":"AXVisualSupportAgent","pid":606,"width":2560,"x":0,"y":0}
[2024-01-16 15:23:10.593] [info]  {"height":1440,"name":"","number":27,"ownerName":"Dock","pid":650,"width":2560,"x":0,"y":0}
[2024-01-16 15:23:10.593] [info]  {"height":1440,"name":"","number":26,"ownerName":"Dock","pid":650,"width":2560,"x":0,"y":0}
[2024-01-16 15:23:10.594] [info]  {"height":254,"name":"","number":16065,"ownerName":"LinkedNotesUIService","pid":11478,"width":254,"x":2306,"y":1186}
[2024-01-16 15:23:10.594] [info]  {"height":76,"name":"","number":11,"ownerName":"AccessibilityVisualsAgent","pid":618,"width":302,"x":100,"y":1280}
[2024-01-16 15:23:10.594] [info]  {"height":300,"name":"","number":10,"ownerName":"AccessibilityVisualsAgent","pid":618,"width":300,"x":1279,"y":720}
[2024-01-16 15:23:10.594] [info]  {"height":84,"name":"","number":19211,"ownerName":"Google Chrome","pid":32027,"width":403,"x":1855,"y":97}
[2024-01-16 15:23:10.594] [info]  {"height":1415,"name":"","number":51,"ownerName":"Finder","pid":654,"width":2560,"x":0,"y":25}
[2024-01-16 15:23:10.594] [info]  {"height":1415,"name":"","number":50,"ownerName":"Finder","pid":654,"width":2560,"x":0,"y":25}
[2024-01-16 15:23:10.594] [info]  {"height":500,"name":"","number":8671,"ownerName":"Code","pid":39825,"width":500,"x":0,"y":940}

System

Is there an easy way to get the relevant system info using Script Kit for these bug reports?

macOS 14.2.1 (M1) Kit 2.3.0

johnlindquist commented 10 months ago

@alexilyaev If believe that happens when Kit.app doesn't have permissions for "Screen Recording". It sounds silly, but I'm pretty sure Screen Recording is needed to access the system API that can get the name of window

CleanShot 2024-01-16 at 07 52 59

alexilyaev commented 10 months ago

Indeed that was the issue. I'm glad that it's a quick fix 😁

I wonder if a script could check the required permission and warn when it's not enabled?

Related issue regarding permissions https://github.com/johnlindquist/kit/issues/1420 Perhaps this permission should be added to the menu as well?