Created
April 26, 2014 12:51
-
-
Save cgiffard/11319369 to your computer and use it in GitHub Desktop.
Nasty hack to get Safari Tabs In Node
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
var applescript = require("applescript"); | |
var getTabs = ' \n\ | |
tell application "Safari" \n\ | |
set urllist to URL of every tab of every window \n\ | |
set namelist to name of every tab of every window \n\ | |
\n\ | |
set theDoc to "" as string \n\ | |
set windowcount to length of urllist \n\ | |
\n\ | |
repeat with cWindow from 1 to windowcount \n\ | |
set ctabList to item cWindow of urllist \n\ | |
set ctabCount to length of ctabList \n\ | |
\n\ | |
repeat with cTab from 1 to ctabCount \n\ | |
set cUrl to item cTab of ctabList \n\ | |
set cName to item cTab of item cWindow of namelist \n\ | |
\n\ | |
set theDoc to theDoc & cName & "₮" & cUrl & linefeed \n\ | |
end repeat \n\ | |
end repeat \n\ | |
return theDoc \n\ | |
end tell '; | |
module.exports = function(cb) { | |
applescript.execString(getTabs, function(err, data) { | |
if (err) return cb(err); | |
var records = | |
data.split(/\n+/) | |
.filter(function(row) { | |
return row.indexOf("₮") >= 0; | |
}) | |
.map(function(data) { | |
return { | |
"name" : data.split("₮").shift(), | |
"url" : data.split("₮").pop() | |
} | |
}); | |
cb(null, records); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment