Last active
February 26, 2024 07:15
-
-
Save roeniss/e4ccee3fe3dd7a2db339e95b72cc9a5e to your computer and use it in GitHub Desktop.
Add a bookmark to Chrome browser
This file contains hidden or 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 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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
with this file, edited and executed 9999 calls.