Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
An Applescript for Camino to Save Tabs to Pinboard. Doesn't work though because of Gecko 1.9 preflighting the request.
--Camino Pinboard save tabs
-- An Applescript to Save Open Tabs to Pinboard, using the Save Tabs functionality:
-- Uses francois2metz fake html5-FormData since Gecko 1.9 doesn't have this
-- Gecko 1.9 preflights all requests except from text/plain which screws the whole thing up
-- (
-- Oh well, it was a nice idea.
property winz : ""
property tabz : ""
property resultz : ""
property source : ""
--Get list of tabs and windows,
tell application "Camino"
repeat with i from 1 to (count browser windows)
repeat with j from 1 to (count of tabs of browser window i)
set tabz to tabz & "{ \"title\": \"" & title of tab j of browser window i & "\", \"url\": \"" & URL of tab j of browser window i & "\"}"
if ((j < (count of tabs of browser window i)) and ((count of tabs of browser window i) > 1)) then
set tabz to tabz & ","
end if
end repeat
set winz to winz & "[" & tabz & "]"
if ((i < (count of browser windows)) and ((count of browser windows) > 1)) then
set winz to winz & ","
end if
set tabz to ""
end repeat
end tell
set resultz to resultz & "{\"browser\":\"camino\",\"windows\":[" & winz & "]}"
set source to ("<html><head></head><body>
<script type=\"text/javascript\" src=\"\"></script>
var params = new FormData();
var req = new XMLHttpRequest();
params.append(\"data\", '" & resultz as string) & "'); // I have an inkling, that should a tab title contain an apostrophe, it may muck this up.\"POST\", \"\", true);
//Don't think these need to be set
//req.setRequestHeader(\"Cache-Control\", \"no-cache\");
//req.setRequestHeader(\"X-Requested-With\", \"XMLHttpRequest\");
//This needs to be set explicity for Gecko, Webkit seems to do by default
req.withCredentials = true
req.setRequestHeader(\"Content-Type\", \"multipart/form-data; boundary=\"+ params.boundary);
req.onreadystatechange = function() {
if (req.readyState == 4) {
window.location.href = \"\";
do shell script "rm -f $HOME/Library/'Application Support'/Camino/caminosavetabstopinboard.html"
do shell script "touch $HOME/Library/'Application Support'/Camino/caminosavetabstopinboard.html"
set js to ((path to home folder as string) & "Library:Application Support:Camino:caminosavetabstopinboard.html") as alias
open for access js with write permission
write source to js
close access js
tell application "Camino"
open js
end tell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.