Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Applescript/Pages cannot find open document

This very simple script does not work:

tell application "Pages"

activate

tell the front document

name

end tell

end tell

All it has to do is give the name of the open document. It says, "Can't get document 1. Invalid index." And, yes, there is an open document.

This behavior has degraded. It worked a few weeks ago and then became increasingly more broken. It's the same with Numbers.


What happened? Is my Applescript corrupted?

MacBook Pro with Retina display, OS X Yosemite (10.10.5)

Posted on Nov 30, 2015 1:13 PM

Reply
10 replies

Nov 30, 2015 2:06 PM in response to SGIII

Thank you. Script Editor was already checked, and I added Automator.

However, the above script also works for me SOMETIMES, but minutes later (and I'm not exaggerating) it will NOT work. A simple edit is what usually breaks it, and undoing the edit does not revive it.

That is why I wonder if my Script Editor (or whatever process behind it) is broken.

Should I reinstall it? A search online does not tell me how to.

Nov 30, 2015 2:13 PM in response to campbellum

Have you tried the simpler things like shutting down and restarting your Mac?


Also you could try the script under a different user account (create a new one if you have to)? If the script works fine under a separate user account then it's possible there's something that got corrupted in your preference files, and someone here will be able to give you guidance on how to fix that.


(My Script Editor was occasionally wonky for a while but now I have no problems. )


SG

Nov 30, 2015 5:23 PM in response to campbellum

I get that "Invalid index" error message if a document isn't already open in Pages. Maybe you don't have a document open before running the script?


The fact that it works sometimes and sometimes doesn't work sometimes is puzzling; have you tried putting a delay statement in the script to see if perhaps the script needs to slow down until the app catches up?


SG

Dec 1, 2015 9:55 AM in response to SGIII

I think you got it! The "delay" seems to fix it. The problem is synchronization between processes. The script races ahead of the application and tries to access the "document" object before it's ready. I should have suspected this, because intermittent problems are often a sign of unpredictable asynchronous actions.

Thanks.

Applescript/Pages cannot find open document

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.