Jump to content
Sign in to follow this  
jazzyjeff

Add Bookmarks to Google Chrome using a GPO

Recommended Posts

jazzyjeff

Hey All,

I'm posting this because it perhaps may help someone else who has encountered a similar issue to be where the goal was to add bookmarks in Google Chrome, but editing the JSON file for the managed bookmarks GPO was only allowing 1 folder in the root of the Bookmarks Bar. In my case I needed 2 folders to be pushed out to our end users, so this script runs at logon for the user ( you could launch the script via a GPO with a logon script), and looks for the Bookmarks file located in the users profile. The script will read this file and insert the bookmarks and folders that have been specified by the coder of this script. The existing Bookmarks that the user had created are not removed, and this script just appends new bookmarks to the existing bookmark bar.

I think this script could be turned into a UDF to make it better, and time permitting I'll probably do this, but for now the code is below:

#include <File.au3>
;#include<Debug.au3> ; Used for Debugging only

$bookmark = "C:\Users\" & @UserName & "\AppData\Local\Google\Chrome\User Data\Default\Bookmarks"
$aBookmark = FileReadToArray($bookmark)
;_DebugArrayDisplay($aBookmark) ; Used for Debugging only

#Region ; 1st Folder in the Bookmarks Bar
$data1 = '            "children": [ {' & @CRLF & _ ; URLs below here
        '               "name": "Yahoo",' & @CRLF & _
        '               "type": "url",' & @CRLF & _
        '               "url": "https://www.yahoo.com"' & @CRLF & _
        '            }, {' & @CRLF & _
        '               "name": "DuckDuckGo",' & @CRLF & _
        '               "type": "url",' & @CRLF & _
        '               "url": "https://www.duckduckgo.com"' & @CRLF & _
        '            } ],' & @CRLF & _
        '            "name": "Search Engines 1",' & @CRLF & _ ; Folder name is set here
        '            "type": "folder"' & @CRLF & _
        '         }, {' & @CRLF
#EndRegion ; 1st Folder in the Bookmarks Bar

#Region ; 2nd Folder in the Bookmarks Bar
$data2 = '            "children": [ {' & @CRLF & _ ; URLs below here
        '               "name": "Bing",' & @CRLF & _
        '               "type": "url",' & @CRLF & _
        '               "url": "https://www.bing.com"' & @CRLF & _
        '            }, {' & @CRLF & _
        '               "name": "Google",' & @CRLF & _
        '               "type": "url",' & @CRLF & _
        '               "url": "https://www.google.com"' & @CRLF & _
        '            } ],' & @CRLF & _
        '            "name": "Search Engines 2",' & @CRLF & _ ; Folder name is set here
        '            "type": "folder"' & @CRLF & _
        '         }, {' & @CRLF
#EndRegion ; 2nd Folder in the Bookmarks Bar

_FileWriteToLine($bookmark, 6, $data1 & $data2) ;Bookmarks file is modified here at line 6. This may need fixing if Google changes how their files are structured

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×