I’ve created a DB to use as a Safari session manager on steroids.
When I have a bunch of windows and tabs opened, I want to save all of them in a group in the form of web archives because this will be easy to search for content and retrieve the web page. It will be also easy to detect and erase duplicates.
I have a working basic framework for the script.
But I didn’t find how to :
-
activate the specific DB (the archives are currently created in the inbox for the active DB)
-
create a group named with today’s date and move the archives in this group
Could you give me some advice ?
tell application id "com.devon-technologies.thinkpro2"
open database "Posix location of the DB"
set this_database to database "SafariTabs"
end tell
tell application "Safari"
repeat with currentWindow in every window
set theTabs to currentWindow's tabs
repeat with theTab in theTabs
set this_URL to the URL of theTab
set this_title to the name of theTab
if exists URL of theTab then tell application id "com.devon-technologies.thinkpro2" to create web document from this_URL name this_title in this_database
end repeat
end repeat
end tell
I’ve refactored and refined the script.
The tabs are now stored in a group named from the date of the save and a progress bar has been added to show what’s going on.
Maybe I’ll add a way to filter out the tabs that are irrelevant (web mails, various social networks, etc.)
set this_Date to (current date) as string
set tabList to {}
tell application "Safari"
repeat with currentWindow in every window
try
set theTabs to tabs of currentWindow
repeat with theTab in theTabs
set this_URL to the URL of theTab
set this_title to the name of theTab
set end of tabList to {this_title, this_URL}
end repeat
on error
"None"
end try
end repeat
end tell
tell application id "com.devon-technologies.thinkpro2"
activate
set this_database to open database "POSIX Path to your DB"
show progress indicator "Archiving all opened tabs..." steps (count of tabList)
try
set this_Group to create location "/" & this_Date in this_database
repeat with i from 1 to count of tabList
set this_title to item 1 of item i of tabList
set this_URL to item 2 of item i of tabList
create web document from this_URL name this_title in this_Group
step progress indicator
end repeat
on error
hide progress indicator
end try
hide progress indicator
end tell