A macro that will create a txt file with a list URLs from all the open tabs in safari.
A second macro that will take that list of URLs and reopen those links as tabs in safari.
This could also be macros that writes a set of bookmarks and then opens and deletes the bookmarks in the 2nd macro.
(basically, I want to "save my work" when I'm done working for the day, and then "open up" to the same tabs, even though I will use safari for personal use in between!)
I think that if any one has any directional suggestions, I should be able to figure it out myself. I'd just love a nudge in the right direction. Thanks!
Tom - oh my god, this is amazing. Works like a charm. I'm trying to go through all the scripts, line by line to understand how it works. One question, since I'm planning on turning my computer off in between running the macro, I am guessing the system variable will get deleted? Or does it save those somewhere, even when the machine is shut down and the restarted?
The macro checks if there exists a KM variable “SafariSessionURLs”.
If not, the first script is run:
The script itinerates through all tabs of all Safari windows appends the URL of each tab to a list (“URLList”). This list is exported (saved) to a KM variable called “SafariSessionURLs”.
If yes, the second script is run:
The script reads the URLs from the “SafariSessionURLs” KM variable back into a list (“URLList”). Then it itinerates through the list and creates a tab from each URL of that list in the current Safari window (or a new one, if there isn’t any).[1]
After the script has run, KM deletes the “SafariSessionURLs” KM variable.
As said, the macro and the scripts are very basic. No error checking, nothing. It is meant as a base where you can build on to create a macro that suits your needs.
1: If the script creates a new window for each URL, check your Safari Preferences > Tabs.
Bear in mind that Safari tabs that are left dormant (not brought into view) for a certain period won't have their URLs returned by AppleScript, which will return missing value in those instances. If this is an issue, you might have better results having the script save the tabs to a designated bookmark folder, which can be reserved for storing and re-storing groups of tabs as you please.
Thanks for the heads-up. I remember now remotly that I once had issues with that (or some similar tab abnormality).
Is this still happening with the current OS and Safari?
Edit/PS:
Just did a quick test with Safari Technology Preview (not Safari): I had 4 windows open with a total of 21 tabs, some of them no more touched (activated) since this morning (>12h). The macro restored 21 tabs.
I can only confirm it is still a phenomenon in Safari on High Sierra, but cannot give any feedback for macOS Mojave or later. I know my resistance to upgrading will eventually have to concede, but I'm holding out for as long as I possibly can, or until I create a USB bootable thumb drive.
OK, did another test, this time with Safari Technology Preview and Safari: Both of them had numerous tabs that were dormant (not brought to foreground) since yesterday evening. For both apps I could now (~18h later) save and restore all tabs with the macro.
The 18h include the system sleep time over night. Safari was hidden all the time, STP not.
So, there are chances that this really has been fixed (I’m on OS 10.14.6), which would be astonishing though. Or it needs still more dormant time to trigger the issue, or other factors (e.g. low on memory). Don’t know.
Tom - this is great. You should publish this separately as your own macro. This is a great addition, for my ability to “context switch” between Work and Fun on the same machine!
If you want, you could change the title of your topic to something like “Save and Restore Safari Session (tabs)” and add the appropriate tags to the topic. This way people will probably find it more easily with the forum search.
OK. Then I will create a new topic with post#2 as OP.
Could you then move the follow-up discussion to the new topic? (It is important because of the issue @CJK mentioned.)
Or should I just refer to the discussion in this topic?