Title: `afterSelectionChanged` triggers "The object no longer exists" error even when a valid object is selected Description: When using th
Title:
afterSelectionChanged
triggers "The object no longer exists" error even when a valid object is selected
Description:
When using the method addEventListener("afterSelectionChanged", ...)
in an ExtendScript script for InDesign, the application consistently throws the following error:
"The requested action could not be completed because the object no longer exists."
This occurs even when:
- A single TextFrame
is manually selected,
- The object is valid (isValid === true
),
- The code is wrapped in a try/catch
,
- An idleTask
is used to defer execution.
Steps to Reproduce:
1. Open an InDesign document.
2. Add the following script:
function onSelectionChanged(event) {
try {
if (app.selection.length > 0 && app.selection[0].isValid) {
alert("Selected: " + app.selection[0].constructor.name);
}
} catch (e) {
alert("Error: " + e.message);
}
}
app.addEventListener("afterSelectionChanged", onSelectionChanged);
- Select a
TextFrame
on the page.
Expected Result:
The script should display the type of the selected object without error.
Actual Result:
An error message appears immediately:
"The requested action could not be completed because the object no longer exists."
System Information:
- InDesign Version: 20.4.1
- OS: macOS 15.3.2
- Language: French
- Script executed from: Scripts Panel
Comment:
This behavior prevents reliable use of afterSelectionChanged
for interacting with the selection. It appears that the event is triggered before the selection is fully stabilized, making app.selection[0]
unusable.
