It's set up to work with pre-selection only, so if your mouse is in the Script Editor to run it, there won't be any pre-selection to query. You'll want to set it up as a custom hotkey for it to work properly. If you just want to test the script, make sure the script editor is active and, before executing the code, make…