Skip to content

Instantly share code, notes, and snippets.

@webbower
Created June 6, 2014 18:26
Show Gist options
  • Save webbower/5102b7456deebf9bbfc5 to your computer and use it in GitHub Desktop.
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
#!/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