Restart app and re-open documents

I've got this applescript to restart an application that I use frequently (for instance after installing fonts). Is there a smart and smooth way to extend it to also re-open all documents it had open? Or would that be too much app-specific code?

set appName to (path to frontmost application as text)
tell application appName to quit
repeat
  tell application "System Events"
    if appName is not in (name of application processes) then exit repeat
  end tell
  do shell script "sleep 0.5"
end repeat
tell application appName to launch

Unfortunately I don't think there is a good way.

Apps can automatically reopen their windows if:
1.) they implement NSWindowRestoration (not all apps do that unfortunately)
2.) "Close windows when quitting an application" is unchecked in System Settings => Desktop & Dock => Windows

1 Like