@lucidnx
The following are a couple of AppleScripts that are a pair.
Briefly, you can run “Export_Brave_Tabs.scpt” in order to create an HTML file named “Brave_Tabs_Backup.html” on the MacOS Desktop. And, you can run “Restore_Brave_Tabs.scpt” in order to create within an existing, new Brave Browser window, the restored Tabs.
The “Export_Brave_Tabs.scpt” backs up all open Tabs from all open Brave Browser windows. Restoration of all Tabs is to a single, new Brave Browser window.
The restoration AppleScript, is not [yet] sophisticated enough to restore sets of Tabs to more than one Brave Browser new window.
In order to upload these scripts to the Brave Community, they are text files ← the contents of which can be copied and pasted into new AppleScript windows, and then those AppleScripts can be saved.
The AppleScript named “Export_Brave_Tabs.scpt” is thus created from file “Export_Brave_Tabs_UPLOAD.txt”
The AppleScript named “Restore_Brave_Tabs.scpt” is thus created from file “Restore_Brave_Tabs_UPLOAD.txt”
'Export_Brave_Tabs_UPLOAD.txt' for making AppleScript named 'Export_Brave_Tabs.scpt'
--
--
-- Export all open Brave tabs to a simple HTML file on the MacOS Desktop
--
--
-- This following AppleScript is now intended to create a backup of all open Brave Browser window Tabs, from all open Brave Browser windows.
--
-- The AppleScript will produce only one HTML file named "Brave_Tabs_Backup.html".
--
-- Thereafter, that backup can be used as a source for restoring such tabs, to a single new Brave Browser window. The restoration AppleScript, named "Restore Brave Tabs.scpt" is my notion, with some help from website 'https://perplexity.ai"
--
-- The following AppleScript, that I named "Export_Brave_Tabs.scpt", was originally written for Google Chrome users, but I significantly changed and added to the original AppleScript, so it works for Brave Browser (MacOS) and does more than the original script. (See notes that credit the original author(s), at end of this script.)
--
-- You can easily read the exported Tabs file, "Brave_Tabs_Backup.html", by opening it with an Internet browser.
--
-- Please Note: I have only tested by using a Brave Browser window that has 4 Tabs.
--
-- The latest MacOS that I have, is v14.8.3 Sonoma, on a mid-2020 MacBook Pro (Intel). I do not know what may happen with MacOS Tahoe and later versions - especially on Apple "M" machines. Apple cannot resist fiddling with what works, and some AppleScript commands / lines, may not work in the future.
--
--
--
--
set report_Title to "Brave Tabs Backup"
set url_list to {}
--
set date_stamp to (current date) as string
set noteTitle to "<h2>" & report_Title & " | " & date_stamp & "</h2>"
--
tell application "Brave Browser"
activate
set allWindows to windows
repeat with w in allWindows
repeat with t in tabs of w
try
set tabTitle to title of t
set tabURL to URL of t
if tabURL is not missing value and tabURL is not "" then
set tabLine to "<p><a href=\"" & tabURL & "\">" & tabTitle & "</a><br>" & tabURL & "</p>"
set end of url_list to tabLine
end if
end try
end repeat
end repeat
end tell
--
-- join lines into HTML text
set AppleScript's text item delimiters to linefeed
set htmlBody to (noteTitle & linefeed & (url_list as text))
set AppleScript's text item delimiters to ""
--
set fileName to "Brave_Tabs_Backup.html"
--
-- These next 2 lines would not work:
-- set desktopFolder to (path to desktop folder as text)
-- set backupFileAlias to (desktopFolder & fileName) as alias
-- So, my workaround, designed to get AppleScript on MacOS 14.8.3 Sonoma, to pay attention regarding what is, and will be:
--
set POSIX_path_to_DskTop_file to (POSIX path of (path to home folder as string) & "Desktop/" & fileName)
set POSIX_file_string to ((POSIX file POSIX_path_to_DskTop_file) as string)
--
-- write the file
--
set fp to open for access POSIX_file_string with write permission
set eof of fp to 0
write htmlBody to fp as «class utf8»
close access fp
--
(*
Found an AppleScript at: "https://veritrope.com/code/export-all-brave-tabs-to-a-text-file/"
Veritrope.com
Export All Brave Tabs to a Text File
VERSION 1.0
September 8, 2012
// INSPIRED BY: Francesco Di Lorenzo (@frankdilo)
20241031 Thursday
Renamed "Chrome" to "Brave"
I made several **Significant Changes** to the original downloaded AppleScript file.
The original AppleScript was written for Google Chrome users.
Now, this AppleScript is written for Brave Browser (MacOS) users.
*)
--
--
--
--
'Restore_Brave_Tabs_UPLOAD.txt' for making AppleScript named 'Restore_Brave_Tabs.scpt'
--
--
-- Restore Brave tabs from an html list of URLs on the MacOS Desktop
--
-- This AppleScript relies on your already having produced an HTML file named "Brave_Tabs_Backup.html" - located on the MacOS Desktop - by using an AppleScript named "Export_Brave_Tabs.scpt"
--
--
--
--
set desktopFolder to (path to desktop folder as text)
set backupName to "Brave_Tabs_Backup.html"
set backupAlias to (desktopFolder & backupName) as alias
--
-- read file contents
set fp to open for access backupAlias
set fileContents to (read fp as «class utf8»)
close access fp
--
-- split into lines (URLs)
set AppleScript's text item delimiters to linefeed
set urlList to text items of fileContents
set AppleScript's text item delimiters to ""
--
-- work towards a list of only the Tabs' URL addresses
--
set urlListText to quoted form of (urlList as text)
--
set fenceLine to "ZZZZZZZZZZZZZZZZZZZZ"
--
tell me to set clean01 to (do shell script "echo " & urlListText & " | sed -e 's@\\<@ @g' -e 's@\\>@ @g' -e 's@\"@ @g' -e 's@ @" & fenceLine & "@g'")
--
set AppleScript's text item delimiters to fenceLine
set nuList to text items of clean01 as list
set AppleScript's text item delimiters to ""
--
set countItemsA to count of items in nuList
--
set nexList to {}
repeat with i from 1 to countItemsA
set thisItem to item i of nuList as string
try
set firstPart to characters 1 thru 4 of thisItem as string
if (firstPart is "http") then
set the end of nexList to thisItem
end if
end try
end repeat
--
-- remove duplicate Tab URL addresses
--
set countItemsB to count of items in nexList
set truList to {}
repeat with n from 1 to countItemsB
set urlAddrss to item n of nexList
if (urlAddrss is not in truList) then
set the end of truList to urlAddrss
end if
end repeat
--
set urlList to truList
--
-- make a new Brave Browser window that includes all of the Tabs stored
--
tell application "Brave Browser"
activate
-- open a fresh window
make new window
set theWindow to front window
set firstTitle to title of theWindow as string
--
set tabsCount to (count of tabs of theWindow)
repeat with u in urlList
set theURL to contents of u
if theURL is not "" then
-- First URL can be set on the existing first tab
if (tabsCount = 1) then
if (URL of tab 1 of theWindow is "about:blank") or (firstTitle is "New Tab") then
set URL of tab 1 of theWindow to theURL
end if
end if
-- after establishing the 1st Tab . . .
if (tabsCount is greater than 1) then
make new tab at end of tabs of theWindow with properties {URL:theURL}
end if
set tabsCount to (tabsCount + 1)
end if
end repeat
end tell
--
--
--
--
In order to Copy, you Copy everything of, and within, the lightly-shaded-gray . . . example:
--
--
-- Export all open Brave tabs to a simple HTML file on the MacOS Desktop
--
And Paste into a new AppleScript window.
You can read the “Brave_Tabs_Backup.html” file on the MacOS Desktop, by using any Internet browser.