Created
February 27, 2015 09:48
-
-
Save xtetsuji/415a9cf8c7bd29203fc4 to your computer and use it in GitHub Desktop.
Google Chrome bookmark dumper for Mac OS X environment.
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 perl | |
# 2015/02/27 OGATA Tetsuji (@xtetsuji) | |
# MIT License | |
use strict; | |
use warnings; | |
use Encode; | |
use JSON::PP; | |
# Default Profile | |
my $bookmark_file = "$ENV{HOME}/Library/Application Support/Google/Chrome/Default/Bookmarks"; | |
if ( !-f $bookmark_file ) { | |
die "Chrome bookmark is not found on path $bookmark_file\n"; | |
} | |
my $bookmark_json = do { | |
open my $fh, '<', $bookmark_file; | |
local $/; | |
<$fh>; | |
}; | |
my $bookmark = decode_json($bookmark_json); | |
my @top_folder_names = grep { ref $bookmark->{roots}->{$_} eq 'HASH' } keys %{$bookmark->{roots}}; | |
my @entire_data; | |
for my $top_folder_name (@top_folder_names) { | |
my $top_folder = $bookmark->{roots}->{$top_folder_name}; | |
my @folder_data = read_data($top_folder); | |
push @entire_data, @folder_data; | |
} | |
for my $line (@entire_data) { | |
print encode("utf-8", "$line\n"); | |
} | |
sub read_data { | |
my $folder = shift; | |
if ( $folder->{type} eq 'folder' ) { | |
my $children = $folder->{children}; # ARRAY | |
return map { read_data($_) } @$children; | |
} elsif ( $folder->{type} eq 'url' ) { | |
my $name = $folder->{name}; | |
my $url = $folder->{url}; | |
return "$name $url"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment