Last active
May 2, 2020 02:26
-
-
Save marcusps/a7bf99c699327aa25154 to your computer and use it in GitHub Desktop.
Chrome Tabs to Markdown
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
# coding: utf-8 | |
# Based on https://gist.github.com/netmute/7374150 | |
require 'date' | |
# Run some AppleScript to fetch open tabs from Chrome | |
input = %x{osascript -e 'tell application \"Google Chrome\"' -e 'set tabList to every tab of window 1' -e 'set urlList to \"\"' -e 'repeat with aTab in tabList' -e 'set aLink to URL of aTab' -e 'set aTitle to Title of aTab' -e 'set urlList to urlList & aLink & \"$\" & aTitle & ASCII character 10' -e 'end repeat' -e 'return urlList' -e 'end tell' 2> /dev/null }.chomp | |
d = DateTime.now.strftime("%a %b %d %Y") | |
puts "\# Chrome tabs for #{d}" | |
# Format it into markdown | |
input.split("\n").each do |line| | |
url, *title = *line.split('$') | |
title = title.join('$') | |
title = url if title == "" | |
puts "[#{title}](#{url})" | |
puts | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Since I'm using the plugin
The Great Suspender
for Chrome on my mac; I needed to parse those url back into normal urls. So I extended your great script as following: