Created
December 8, 2022 15:44
-
-
Save irace/9bece8961075655516184e534ba83586 to your computer and use it in GitHub Desktop.
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 ruby | |
# frozen_string_literal: true | |
# Required parameters: | |
# @raycast.schemaVersion 1 | |
# @raycast.title Fetch Markdown link from Chrome | |
# @raycast.mode silent | |
# Optional parameters: | |
# @raycast.icon 🔗 | |
# Documentation: | |
# @raycast.description Fetch Markdown Link from Chrome | |
# @raycast.author Bryan Irace | |
# Heavily inspired by dbalatero's https://github.com/dbalatero/dotfiles/blob/c70a9acefffa753aea72b9d6cc2aaa2f94108b43/hammerspoon/rich-link-copy.lua | |
require 'open3' | |
require 'cgi' | |
def osascript(script) | |
stdout, = Open3.capture3('osascript', *script.split(/\n/).map { |line| ['-e', line] }.flatten) | |
stdout | |
end | |
def pbcopy(arg) | |
IO.popen('pbcopy', 'w') { |io| io.puts arg } | |
end | |
def escape_and_strip(arg) | |
CGI.escapeHTML(arg.strip!) | |
end | |
def strip(arg) | |
arg.strip! | |
end | |
title = strip osascript <<-END | |
tell application "Google Chrome" | |
get title of active tab of first window | |
end tell | |
END | |
url = escape_and_strip osascript <<-END | |
tell application "Google Chrome" | |
get url of active tab of first window | |
end tell | |
END | |
markdown = "[#{title}](#{url})" | |
pbcopy markdown | |
puts "Copied '#{title}' as formatted Markdown to clipboard!" |
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 ruby | |
# frozen_string_literal: true | |
# Required parameters: | |
# @raycast.schemaVersion 1 | |
# @raycast.title Fetch RTF link from Chrome | |
# @raycast.mode silent | |
# Optional parameters: | |
# @raycast.icon 🔗 | |
# Documentation: | |
# @raycast.description Fetch RTF Link from Chrome | |
# @raycast.author Bryan Irace | |
# Heavily inspired by dbalatero's https://github.com/dbalatero/dotfiles/blob/c70a9acefffa753aea72b9d6cc2aaa2f94108b43/hammerspoon/rich-link-copy.lua | |
require 'open3' | |
require 'cgi' | |
def osascript(script) | |
stdout, = Open3.capture3('osascript', *script.split(/\n/).map { |line| ['-e', line] }.flatten) | |
stdout | |
end | |
def escape_and_strip(arg) | |
CGI.escapeHTML(arg.strip!) | |
end | |
title = escape_and_strip osascript <<-END | |
tell application "Google Chrome" | |
get title of active tab of first window | |
end tell | |
END | |
url = escape_and_strip osascript <<-END | |
tell application "Google Chrome" | |
get url of active tab of first window | |
end tell | |
END | |
html = "<a href=\"#{url}\">#{title}</a>" | |
# https://assortedarray.com/posts/copy-rich-text-cmd-mac/ | |
hex = `echo "#{html}" | hexdump -ve '1/1 "%.2x"'` | |
osascript <<-END | |
set the clipboard to {text:\" \", «class HTML»:«data HTML#{hex}»} | |
END | |
puts "Copied '#{title}' as RTF to clipboard!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment