Open vs. OpenDocument

I have read that you cannot guarantee which one fires first if you open a document or drag a doc onto the app icon.

But is there a way to get an indicator that the app is being opened with a document/file
vs. just opening the application via Open?

I know the file is passed as “item” to OpenDocument but I also need to know in Open if a document is passed.

Set up app things in Open, and set up document things in OpenDocument. If you muddle the two that’s when you face problems.

Take a look at the documentation. I think it’s pretty clear the different app.OpenDocument and App.NewDocument:

App.Open will always be called, these two depend on how the application was launched.

Don’t forget Window.Open, which is called after everything else. It can be a good spot to finalize settings. Don’t try to put everything in one place. Each of the four “Open” events has its purpose.

If OpenDocument is NOT called then I need to open a basic document and/or call new document.
So how does Open know that OpenDocument is called?

I can set up a global variable to flag that but if I can’t guarantee which one is called first then that doesn’t work.

If you hover over the quote and click the spyglass it will take you to the post in context which has the documentation links.

Doh! I get it now. I think I have my NewDocument stuff in App.Open which is causing the problem.

There is not any way though to know if App.Open occurs before OpenDocument or NewDocument?
i.e. you can’t guarantee which one will go first? If main app screen is not loaded I think it throws errors if I try to open a document.

(from the other topic)

“Main app screen” sounds like a window, and should be separated from any app.Open code. You might want to use a Timer to get an event that happens after everything (which I suspect is the subject of Tim’s link, above) and not have a default window set in your app. In the timer, open a new document if there isn’t one already open (WindowCount > 0).