Repository Public Research preview
1-- Download a URL from inside the page — with the site's cookies and sign-in — and print it as2-- base64. Pipe the output into a file:3-- osascript fetch-base64.applescript <window-id> <tab-index> '/path/or/url' | base64 -D > file.bin4-- Prints "HTTP <status>" on stderr-like first line when the server refuses. Same-origin URLs only5-- (the browser's own rules). Suited to files up to a few megabytes; larger ones need chunking.6on run argv7 set w to (item 1 of argv) as integer8 set t to (item 2 of argv) as integer9 set u to do shell script "/usr/bin/python3 -c 'import sys,urllib.parse; print(urllib.parse.quote(sys.argv[1], safe=\"\"))' " & quoted form of (item 3 of argv)10 -- do JavaScript cannot wait for a promise, so the request is synchronous.11 set js to "(function(u){var x=new XMLHttpRequest(); x.open('GET',u,false); x.overrideMimeType('text/plain; charset=x-user-defined'); x.send();" & ¬12 "if(x.status<200||x.status>=300) return 'HTTP '+x.status; var s=x.responseText, b=''; for(var i=0;i<s.length;i++) b+=String.fromCharCode(s.charCodeAt(i)&255); return btoa(b);})(decodeURIComponent('" & u & "'))"13 tell application "Safari"14 return do JavaScript js in tab t of window id w15 end tell16end run17