I tried creating a loop to wait for an active document to be opened, but this makes Adobe freeze, even if I open Adobe by double clicking on a document (and thus opening an active document)?
Any advice on how I could tickle this?
You can't use a loop for the reasons you've already observed. You need to use an interval so that Acrobat has time to do other stuff in between when your code runs. However, I strongly advise you research other solutions. Do you really want this to run on every file that gets opened?
Thank you for your response. I have tried the following:
Create "test.js" in:
With the following contents:
Uppon opening a random PDF, I see the "hi" messagebox.
When I try to use the timeinterval, and put the following code into the test.js, it doesn't work anymore:
However, when I run this code in the debug window, it seems to work perfectly.
You must use a variable to save the return value of setInterval, even if you don't use it for anything else.
Thank you for your patience. As you can see, I'm taking my first babysteps in this world. By using the timeout function, I had the same problem when using a while loop to wait a few seconds:
timeout = app.setInterval("createalert()",5000);
Even though I have a document open, this.documentFileName still gets returned undefined. My guess is because even though I have only one PDF open, the code does not get applied to the current pdf, as it would if I just run it in the debugger window.
And don't try to use "this" in a timer. What should it even be? The documentation tells you when "this" is valid, and what it means, and fails to tell you quite forcefully enough NEVER USE IT OTHER TIMES.
Also, when the folder-level script is launched when you open the application (by double-clicking a file, for example) it is executed before the file is actually opened, so you can't access it at that time.
Perhaps we weren't clear enough. DON'T DO THIS. Please describe your aim, so we can help you find a way that will work.
try67: Makes a lot of sense. Will code inside a folder-level script somehow be able to access the opened document at some point though?
@test screen name:
Sure, if you put that code in a function and call the function after the file has been loaded.
You can use an Action to process your files. Forget about the idea of processing any file that is opened. It might be technically feasible (doubt it, as there are issues with the files being disclosed to your script, beyond those you've already encountered), but it's not a good idea.
Ok - Stop. Slowly back away from your keyboard. Don't make any sudden movements.
The only way to do what you want to do is to create an a function that runs at a specified interval that will collect the unique ids of every document, somehow indicate which ones it has already scrolled to the page you want, look for any new documents that have been opened and have not run the scroll code, scroll them, add them to the list of scrolled documents, and then remove any documents from the list that may have been closed.
While it's possible, for this code to be of any use, the interval would need to run at a fairly frequent interval and that's going to just kill Acrobat and slow down everything else it's doing.
YOU DO NOT WANT TO DO THIS!
Please describe your goal... be specific. Trust me on this, creating an application level event handler to run every time a document gets opened is far more complicated than it seems.
And are you SURE you want to apply it to every PDF you open? What about, for example, PDF files viewed in a web browser, which might well run your code.
I understand the concern, and yes this is a niche idea for which I have yet to hear a good alternative to my initial problem (I am trying to look for a solution in a constructive way). I agree that you need to build in checks. The first would for instance be limiting it to certain document format name. If I call "app.activeDocs" in the timer function, I never get a return value (even if a document is opened), which makes me believe that you can't seem to call document specific functions, try67?
I did some tests and it only works (for me) if the file is already disclosed, which kind of beats the purpose, as you would need to embed a script in it to make it disclosed in the first place...