I wrote an AppleScript (saved as an app) awhile back that opens a new Safari Private window to a web-app site that requires a private window in order to have multiple windows to that site open and not step on each others' toes. It works great. I use it every day.
One side-effect though is that after I run that app/script (which I tend to do about 3 times a day), the next time I click any URL in any other app (e.g. Slack - usually I'm clicking a GitHub link), it opens by default in a private window, presumably because Safari is remembering that the last time I opened a browser window, I did so with Command + Shift + N (via that script) to get a private window.
When that happens, I don't get logged in automatically to whatever site, so I either have to manually log in or open a new "public" window and copy over the URL.
Is there some way (e.g. as a clean-up step in the AppleScript) to tell Safari that the next time I click a link, I want to resume using "public" windows?
I already tried adding a step to the script to open and close a public window, but that didn't work. Apparently I have to actually go to a website in order for normal link-clicking behavior to resume defaulting to public windows. Besides, I don't like the open/close of an otherwise useless window.
UPDATE: I just confirmed that it's Keychain Access that is causing this behavior. The step at which the defaulting to private windows starts is after selecting login info from the autofill option in the login field of the site in the private window. I don't even have to submit the form. Any link clicked after selecting an account to login with using autofill in the private window causes the next clicked link to default to a private window.
UPDATE2: I think I was wrong in my last update. It appears as though - if you click a link somewhere (e.g. in Mail.app) and the front-most Safari window is a private window, the new window will also be a private window. I guess that sort of makes sense, which makes my original question more relevant: how to explicitly open a link in a public window when the frontmost window is a private window (or how to default to a public window for clicked links regardless of the frontmost window)?