Skip to content

Instantly share code, notes, and snippets.

@vdm
Last active October 27, 2025 13:35
Show Gist options
  • Select an option

  • Save vdm/4c56b56442002a03889906de588b3926 to your computer and use it in GitHub Desktop.

Select an option

Save vdm/4c56b56442002a03889906de588b3926 to your computer and use it in GitHub Desktop.
Paste browser copied html to terminal
#!/usr/bin/osascript
# firefox 142.0.1 (aarch64) truncates selected HTML at first code block on chatgpt.com/c/*
# chrome 141.0.7390.123 (arm64) does not
# but pbpaste pastes plain text pasteboard only, losing headings and code blocks,
# even though a HTML pasteboard was also copied by Chrome
#
# [copy from browser text selection]
# $ osascript -e 'clipboard info'
# «class HTML», 44430, «class utf8», 12288, «class ut16», 24302, string, 337, Unicode text, 24300
# $ pbpaste | less
# [plain text]
#
# not a Thing:
# $ pbpaste -Prefer html
# Markdown:
# | pandoc -f html -t gfm+pipe_tables+raw_html --wrap=preserve
use framework "AppKit"
set pb to current application's NSPasteboard's generalPasteboard()
set htmlType to "public.html"
set d to pb's dataForType:htmlType
if d = missing value then error "No HTML on clipboard"
set s to (current application's NSString's alloc()'s initWithData:d encoding:(current application's NSUTF8StringEncoding))
if s = missing value then set s to (current application's NSString's alloc()'s initWithData:d encoding:(current application's NSWindowsCP1252StringEncoding))
s as string
# https://gist.github.com/vdm/4c56b56442002a03889906de588b3926
# https://chatgpt.com/share/68ff713d-dc90-800a-875c-cd46d4f2248a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment