Last active
December 30, 2023 22:15
-
-
Save mcint/561f72e6baa3e5c68c2577b04dad788c to your computer and use it in GitHub Desktop.
Bash script to call Applescript to export a list of urls and titles, grouped by window, and output in the format of OneTab.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Javascript for Automation | |
-- *this* works, but simple naive JS-literate variants do not. | |
-- prepending newlines b/c values are returned with implicit trailing "," | |
Application("Brave") | |
.windows.tabs() | |
.map(w=>"\n"+ | |
w.map(t=>"\n"+ | |
t.url()+" | "+t.title())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# bash function | |
tabs-brave () | |
{ | |
: written: 2023-01-05T16:46:50 mcint@mcint-mbp.local; | |
_args="$@"; | |
_file=~/Documents/tabs/brave/tabs.$(date +%FT%T).${_args// /-}.log; | |
echo -n "$_file"; | |
_count=$(osascript ~/.iclouds/com~apple~ScriptEditor2/Documents/Tabs-Brave.scpt | tee -a "$_file" | grep -ve '^#' -e '^$' | wc -l;); | |
echo "$_count" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- use AppleScript to export tabs from chromium... or any? native browser on macOS | |
-- https://gist.github.com/mcint/561f72e6baa3e5c68c2577b04dad788c | |
-- output tabs in format compatible with OneTab | |
-- faster, low-touch (but macOS-only) way of exporting tabs | |
set nl to linefeed | |
set cntT to 0 | |
set cntW to 0 | |
set out to "# tabs-brave. OneTab format." & nl | |
tell application "Brave Browser" | |
set wts to properties of tabs of windows | |
repeat with w in wts | |
repeat with t in w | |
set out to out & nl & URL of t & " | " & title of t | |
set cntT to 1 + cntT | |
end repeat | |
set out to out & nl | |
set cntW to 1 + cntW | |
end repeat | |
end tell | |
set out to out & "# end w:" & cntW & ", t:" & cntT & nl | |
out |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment