Saving window state is certainly possible. All you have to do is collect the "target", "name" and "frame" of each window in each app and save them to a Dictionary, probably with a structure like:
{
{application:"Safari", windows:{{target:"Doc1", name:"foo", windowFrame:"x1,y1,w1,h1"},{target:"Doc2", name:"bar", windowFrame:"x2,y2,w2,h2"}}}
{application:"Preview", windows:{{target:"Doc1", name:"foo", windowFrame:"x1,y1,w1,h1"},{target:"Doc2", name:"bar", windowFrame:"x2,y2,w2,h2"}}}
...
}
"name" and "frame" is easy. The problem will be "target", needed so you can open the correct document/folder/URL, so you'll probably have to do this one window at a time for each application, collecting the target and closing them as you go. For some apps you can use the (new in KM v11) %FrontDocumentPath%
token to get the window's target. For browsers you'll have to get the window's current URL, for the Finder it'll be %FinderInsertionLocation%
, and so on.
Probably best to divide your apps into two groups:
- Those that re-open windows "properly" on re-launch. You just quit the app without closing any windows, re-launch it and the windows come back as they were
- Those that don't, and for which you'll have to save state for later
That'll minimise the amount of work you need to do. And if you can name some "problem" apps people might be able to help with routines for them.