Skip to content

Instantly share code, notes, and snippets.

@roeniss
Last active February 26, 2024 07:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save roeniss/e4ccee3fe3dd7a2db339e95b72cc9a5e to your computer and use it in GitHub Desktop.
Save roeniss/e4ccee3fe3dd7a2db339e95b72cc9a5e to your computer and use it in GitHub Desktop.
Add a bookmark to Chrome browser
#!/usr/bin/env bash
#
# Prerequisite: add a new bookmark directory in root directory.
#
# Usage: ./add_bookmark.sh "https://github.com/roeniss" "my github profile"
#
# Strongly recommend: Quit Chrome compeletely before execution.
#
# This is tested on m1 macbook, Ventura 13.3.1, 2023.
#
URL=$1
NAME=$2
BOOKMARKS_FILE=~/Library/Application\ Support/Google/Chrome/Default/Bookmarks
TMP=$(mktemp)
# backup
cp "$BOOKMARKS_FILE" ~/Downloads/Bookmarks.backup
# add a single bookmark into the last folder in root directory, then save it to tmp file
jq --arg URL "$URL" --arg NAME "$NAME" '.roots.bookmark_bar.children[.roots.bookmark_bar.children | length - 1].children[
.roots.bookmark_bar.children[.roots.bookmark_bar.children | length - 1].children | length
] |= . + {
"meta_info": {
"power_bookmark_meta": ""
},
"name": $NAME,
"type": "url",
"url": $URL
}' "$BOOKMARKS_FILE" > "$TMP"
# update with tmp file
cat "$TMP" >"$BOOKMARKS_FILE"
echo "Done"
@roeniss
Copy link
Author

roeniss commented May 9, 2023

How/When I use this: I'm using Alfred5, which can open a specific bookmark page very fast. Recently, I thought that it would be better to add all of my organization's repositories instead of adding one by one when I newly visited. So I added all of them.

gh repo list -L 9999 $MY_ORG > repos.txt

with this file, edited and executed 9999 calls.

./add_bookmark.sh "https://github.com/MY_ORG/foo" "foo"
./add_bookmark.sh "https://github.com/MY_ORG/bar" "bar"
./add_bookmark.sh "https://github.com/MY_ORG/foo-bar" "foo-bar"
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment