Open and close a note file for any app launched or quit

Edit - with your help, I've made progress; please see my posts later in the thread.

Problem: I want an Omni Outliner file of notes specific to a given application to open when that app launches, and to close when it quits.

Solution: For each app, I create a unique OO file named "appName Notes" all saved in the same folder.
For each app, I make two macros: "appName Notes - Open" and "appName Notes - Close" They do what their titles imply: on app launch, one opens the specific OO file, and the other closes it when the app quits.

Is there a more elegant and efficient way to do this?

Could a macro look at any app launch, compare it to the OO files in the folder, and launch the approriate file if it exists? Could the same macro close that OO file when the app quit?

I'm finding the notes to be very handy, but there are an inconvenient number of steps to quickly set it up for a new App.

Thanks for your help!

(edited so appNames would show up in post. D'oh!)

Opening the file should be fairly easy… you need the name of the application and the directory where the files are used, and then you just put together a potential filename. Then it's just a matter of checking to see if that file exists.

Closing the file would be trickier. If you just wanted to quit the app, that's easy enough, but if you just want to close a specific file, you'd probably need to switch to the app and try to find a window with a matching title to the filename. If OmniOutliner supports AppleScript, that may help. If it doesn't, that's going to be a much tougher task.

You can use %TriggerValue% with a macro that runs when "Any Application" quits, you can get that application's name. I assume there that variable might also work for an '"Any Application" launches' macro.

Maybe that will help get you started.

Yes, that should be easy enough if you use a file naming convention much like you already are using:
<Full App Name as KM Sees it> Notes.oo

Then, you just need one macro that is triggered when any of the apps of interest is launched. The Macro gets the app name, and constructs the OO file from that.

Make sense?
Questions?

@anamorph, I hope you don't mind that I have revised your topic title to better reflect the question you have asked.

FROM:
There's got to be a more elegant/efficient way to do this

TO:
How Do I Open a Specific Omni Outliner File When an App Launches?

This will greatly help you attract more experienced users to help solve your problem, and will help future readers find your question, and the solution.

If you'd like to refine the Title, please feel free to do so.

Thank you for the effort to attract more help.

I'm going to retitle it, because I solved the problem you put in the title before I posted. I wanted help making it more resuseable and gerneralized. (If those are the correct terms.)

As it stands, I have to make a new open and close macro for each app for which I set up notes.

I imagine there should be a way to make a single "open notes" macro and a single "close notes" macro that work for every app that has a notes file containing the app name in a particular folder. I have the concept, but I'm having trouble working out how to do it in KM.

Using your suggestions, I've made progress. I have two generalized macros: one to open the notes file, and one to close it. The opening macro takes the TriggerValue of the App Launch and uses it to launch the OO file that contains the name in the App Notes Folder.

The close macro uses the Omni Outliner Window menu to bring the note file to the front if they exist, and then closes the window.

Here's what they look like -

Open notes:

46%20PM

Close notes:

52%20PM

New Problem: The Macro doesn't work with all apps. I carefully checked the names of all existing app Notes files to make sure their names matched the TriggerValue given by launching the app. Some apps like Scrivener fail to open the Omni Outliner file, even though the name perfectly matches the TriggerValue.

However, if I open the OmniOutliner file manually and then Quit Scrivener, the Close Macro will close the Notes window. This leads me to believe that the path is malformed, but I can't see how. I've even tried displaying the TriggerValue in a text window and pasting it by hand into the title of the notes file.

There are about three apps so far that don't work with this macro, despite using the TriggerValue from the app.

EDIT: ADDITIONAL INFO:

I've gotten the If statement to work if I change it to "something exists." It will not work if it is set to "file exists." Why does KM recognize the path well enough to launch the file, but returns FALSE for "file exists at this path"? (P.S., the two paths are clipboard copies of each other. I tried using a variable for a test, but I couldn't get KM to accept my path variable.)

Any suggestions are appreciated.