Created
June 6, 2014 18:26
-
-
Save webbower/5102b7456deebf9bbfc5 to your computer and use it in GitHub Desktop.
Takes an export file from Pocket (export format as of 2014-06-06) and imports the Unread items into Safari's Reading LIst
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 php | |
<?php | |
// OSA Script command line template | |
$osascriptTpl = 'osascript -e "tell application \"Safari\" to add reading list item \"%s\""'; | |
// Read in export file from Pocket app | |
$pocketList = file_get_contents("{$_ENV['HOME']}/Downloads/ril_export.html"); | |
// Get the ul that contains my unread list | |
$dom = new DOMDocument(); | |
@$dom->loadHTML($pocketList); | |
$unread = $dom->getElementsByTagName('ul')->item(0); | |
// Loop through the list and extract the URLs to pass into the AppleScript | |
$counter = 0; | |
foreach ($unread->childNodes as $li) { | |
if ($li->nodeName === 'li') { | |
$url = $li->firstChild->attributes->getNamedItem('href')->value; | |
echo "Adding '{$url}' to Reading List\n"; | |
passthru(sprintf($osascriptTpl, $url)); | |
$counter++; | |
} | |
} | |
// Output final count | |
echo "\nAdded {$counter} items to Reading List"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment