Last active
June 14, 2021 02:16
-
-
Save eddy-22/f1b1e49ba5da7b72ac8f8f5f64624cba to your computer and use it in GitHub Desktop.
[Save Tabs Script] Saving tabs for later in an HTML file #shell
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
#!/usr/bin/env bash | |
save-tabs () { | |
local dest="${1:-$HOME/tabs.html}" | |
local SAVE_TABS=$(cat <<EOS | |
set text item delimiters to linefeed | |
tell application "Google Chrome" to set taburls to URL of tabs of window 1 as text | |
set urls to every text item of taburls | |
set filename to (choose file name with prompt "Save Tab Set" default name "tabs.html" default location path to desktop) | |
try | |
set tabfile to open for access file filename with write permission | |
write "<html><head><script type='text/javascript'>" to tabfile | |
write "function load() { " to tabfile | |
repeat with u in urls | |
write "window.open('" to tabfile | |
write u to tabfile | |
write "', '_blank'); " to tabfile | |
end repeat | |
write "setTimeout(function() { window.close(); }, " & (1000 * (count of urls)) & "); }" to tabfile | |
write "</script></head><body onload='load()'></body></html>" to tabfile | |
close access the tabfile | |
on error errMsg number errNum | |
display dialog errMsg | |
end try | |
EOS | |
) | |
osascript -e "$SAVE_TABS" | |
} | |
save_tabs $@ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment