Chrome Bookmark Management

Chrome Bookmark Management: A Fun Guide to Organizing Your Digital Chaos

Loading

 

Author: Nawaz Kazi

Ever find yourself frantically hitting Ctrl+D like a caffeinated squirrel, bookmarking every “life-changing” article you’ll “definitely read later”? Yeah, me too. My Chrome bookmark bar looks like a digital yard sale of abandoned hopes and dreams. But fear not, fellow bookmark hoarders! I’ve got a PowerShell script that’s about to expose all your bookmark-collecting sins.

The “I’ll Read It Later” Intervention

Let’s be honest – we all have that “Read Later” folder that should be renamed to “Read Never.” Here’s a PowerShell script that’s like a Marie Kondo for your digital life, but instead of asking if things spark joy, it’s going to show you just how many bookmarks you’ve been ghosting.

The PowerShell Script for Chrome Bookmarks

Below is the complete PowerShell script that will help you access, parse, and list your recent Chrome bookmarks.

# Chrome bookmarks file path
$chromeProfilePath = [System.Environment]::GetFolderPath('LocalApplicationData')
$bookmarksPath = Join-Path -Path $chromeProfilePath -ChildPath "Google\Chrome\User Data\Default\Bookmarks"

# Check and read the bookmarks file
if (Test-Path -Path $bookmarksPath) {
    $bookmarksJson = Get-Content -Path $bookmarksPath -Raw | ConvertFrom-Json

    $bookmarksList = New-Object System.Collections.Generic.List[Object]

    # Recursive function to process bookmarks
    function Search-Bookmarks {
        param ($node, $folderPath = "")
        if ($node.url) {
            $bookmark = New-Object PSObject -Property @{
                Name = $node.name
                URL = $node.url
                FolderPath = $folderPath
                DateAdded = Get-Date -Date ([datetime]'1601-01-01').AddTicks($node.date_added)
            }
            $bookmarksList.Add($bookmark)
        }
        if ($node.children) {
            $newFolderPath = $folderPath + "\" + $node.name
            foreach ($child in $node.children) {
                Search-Bookmarks -node $child -folderPath $newFolderPath
            }
        }
    }

    # Start processing
    foreach ($root in $bookmarksJson.roots.psobject.Properties) {
        Search-Bookmarks -node $root.Value
    }

    # Sort and list the last 10 bookmarks
    $last10Bookmarks = $bookmarksList | Sort-Object DateAdded -Descending | Select-Object -First 10

    # Output
    if ($last10Bookmarks) {
        $last10Bookmarks | ForEach-Object {
            "Bookmark: $($_.Name)"
            "URL: $($_.URL)"
            "Folder Path: $($_.FolderPath)"
            "Date Added: $($_.DateAdded)"
            "`n"
        }
    } else {
        "No bookmarks found."
    }
} else {
    "Bookmarks file not found at path: $bookmarksPath"
}

 

Step-by-Step Breakdown of the PowerShell Script

 

1. Locate the Chrome Bookmarks File

To access your Chrome bookmarks, the script starts by defining the file path where Chrome stores bookmarks by default:

$chromeProfilePath = [System.Environment]::GetFolderPath('LocalApplicationData') $bookmarksPath = Join-Path -Path $chromeProfilePath -ChildPath "Google\Chrome\User Data\Default\Bookmarks"

Chrome stores bookmarks in JSON format in your local application data folder, specifically under User Data\Default\Bookmarks.

2. Check if the Bookmarks File Exists

To ensure smooth operation, the script checks if the bookmarks file exists at the specified path:

if (Test-Path -Path $bookmarksPath) { $bookmarksJson = Get-Content -Path $bookmarksPath -Raw | ConvertFrom-Json

This code converts the JSON content of the bookmark file into a PowerShell object, making it easier to work with the bookmark data.

3. Define a Recursive Function to Process Bookmarks

This script section is essential for parsing the hierarchical structure of Chrome bookmarks. Chrome bookmarks are organized in folders, so a recursive function helps traverse each folder and retrieve bookmarks individually:

function Search-Bookmarks { param ($node, $folderPath = "") if ($node.url) { $bookmark = New-Object PSObject -Property @{ Name = $node.name URL = $node.url FolderPath = $folderPath DateAdded = Get-Date -Date ([datetime]'1601-01-01').AddTicks($node.date_added) } $bookmarksList.Add($bookmark) } if ($node.children) { $newFolderPath = $folderPath + "\" + $node.name foreach ($child in $node.children) { Search-Bookmarks -node $child -folderPath $newFolderPath } } }

This function checks each node for a url property (indicating a bookmark) and adds it to $bookmarksList. If the node has children, the function calls itself to go through each child node.

4. Process Each Bookmark Root

Once the Search-Bookmarks the function is defined, the script loops through the root folders (like Bookmarks Bar and Other Bookmarks), initiating the recursive search for each one:

foreach ($root in $bookmarksJson.roots.psobject.Properties) { Search-Bookmarks -node $root.Value }

5. Sort and Display the Last 10 Bookmarks

Finally, the script sorts the bookmarks by date and displays the last 10 {Modify this value if you want to search more than this} bookmarks:

$last10Bookmarks = $bookmarksList | Sort-Object DateAdded -Descending | Select-Object -First 10

It prints each bookmark’s name, URL, folder path, and date added. If no bookmarks are found, it will display a message.

Chrome Bookmark

Pro Tips for the Bookmark-Challenged

  • Run this script monthly to face your bookmarking reality
  • Share the results with friends to feel better about your digital hoarding habits

Remember, the first step to recovery is admitting you have a bookmark problem. This PowerShell script is here to help you face that truth, one forgotten URL at a time.

Leave a Comment

Your email address will not be published. Required fields are marked *