Script that checks for apps with open window asks 'Where is Electron" in Electron apps
I have a script that prints the bundle ids for all apps with open windows. When an Electron app is open (for example VSCode) the script asks "Where is Electron" and it shows all apps in the Applications folder except Electron apps. How to fix this behavior?
The Code:
set bundles to {}
tell application "System Events"
set names to get the name of every process whose visible is true
end tell
repeat with name in names
set bundles to bundles & id of application name
end repeat
You need to use a different name for your repeat statement’s loop variable - the term name
is an AppleScript property and is also in System Events
scripting dictionary. Your usage isn’t generating a syntax error, but it is probably causing more confusion than usual and is winding up targeting the wrong item (welcome to AppleScript).
You can use pipes around variable names like this where there may be a conflict (e.g. |name|
), but CJK’s solution also avoids the repeat statement altogether.