Delete all Dropbox shared links #

via JavaScript:

// This script automates the removal of all shared links from your Dropbox account. 
// Navigate to https://www.dropbox.com/share/links, open the browser console, and paste the JavaScript code below.
// Optional: To delete only specific types of links (i.e., View or Edit links), 
// edit the `deleteLinkTexts` array to include only the types of links you want to remove.
// By default, the script will target both "Delete view link" and "Delete edit link" options.
// Script source: https://www.dropboxforum.com/t5/Create-upload-and-share/remove-all-shared-links/m-p/710562/highlight/true#M73731

async function pause(ms) {
    return new Promise(resolve => {
        setTimeout(() => {
            resolve();
        }, ms);
    });
}

async function deleteLinks() {
    const deleteLinkTexts = ["Delete view link", "Delete edit link"]; // Both options
    let items = document.querySelectorAll('.share-page-row-actions [data-testid="open-menu-button"]');

    for (let i = 0; i < items.length; i++) {
        items[i].click(); // Click the submenu button to open the menu
        await pause(1000); // Adjust the pause duration as needed

        // Find and click the appropriate delete link option
        const deleteLinkOption = Array.from(document.querySelectorAll('.dig-Menu-row-title')).find(item => deleteLinkTexts.includes(item.textContent));
        if (deleteLinkOption) {
            deleteLinkOption.click(); // Click the delete link option
            await pause(1000); // Adjust the pause duration as needed

            // Find and click the delete button
            const deleteButton = document.getElementsByClassName("dbmodal-button");
            if (deleteButton.length > 0) {
                deleteButton[0].click();
                await pause(1000); // Adjust the pause duration as needed
            }
        }

        items = document.querySelectorAll('.share-page-row-actions [data-testid="open-menu-button"]'); // Refresh items
    }
}

deleteLinks();

or via watermint toolbox:

  1. Install watermint toolbox

  2. List shared links:

    % tbx dropbox file sharedlink list
    ...  
    | tag    | url                        | name    | expires | path_lower      | visibility |
    |--------|----------------------------|---------|---------|-----------------|------------|
    | file   | https://www.dropbox.com... | foo.jpg |         | /photos/foo.jpg | public     |
    | file   | https://www.dropbox.com... | bar.jpg |         | /photos/bar.jpg | public     |
    | folder | https://www.dropbox.com... | Baz     |         | /baz            | public     |
    
    The report generated: /Users/user/.toolbox/jobs/20240913-094617.OPY/report/shared_link.csv
    The report generated: /Users/user/.toolbox/jobs/20240913-094617.OPY/report/shared_link.json
    The report generated: /Users/user/.toolbox/jobs/20240913-094617.OPY/report/shared_link.xlsx
    The command finished: 2.16s
  3. Delete a single shared link:

    % tbx dropbox file sharedlink delete -path /photos/foo.jpg
    
    Removing link `https://www.dropbox.com...` that point to `/photos/foo.jpg`
    
    | status  | reason | input.tag | input.url                  | input.name | input.expires | input.path_lower | input.visibility | result |
    |---------|--------|-----------|----------------------------|------------|---------------|------------------|------------------|--------|
    | Success |        | file      | https://www.dropbox.com... | foo.jpg    |               | /photos/foo.jpg  | public           |        |
    ...

    or all shared links by extracting the paths from the path_lower column in shared_link.csv with awk and feeding them to tbx via xargs:

    % awk -F ',' 'NR>1 {print $5}' shared_link.csv | xargs -I {} tbx dropbox file sharedlink delete -path "{}"

    (tbx includes a dropbox team sharedlink delete links command to batch delete shared links for Teams accounts.)

Related

/misc | Sep 14, 2024


Subscribe or visit the archives.