It's not a perfect solution but it should help you out. Following preformatted text is a very simple script that can open a series of bookmarks which are tagged with a particular keyword. Each bookmark would be opened in the browser selected as default for the bookmark's URL type.
Script
#!/system/bin/sh
list=/data/media/0/bms_list;
keyword="$1";
browser="$2";
mkfifo $list;
# force-stop default browser
[[ "$browser" ]] && am force-stop "$browser";
# get URL of bookmarks associated with the supplied keyword
content query --uri content://org.mozilla.firefox.db.browser/bookmarks --projection url --where "keyword='$keyword'" | busybox sed 's/.*url=//g' > $list &
# Take each URL from the saved output and launch it using the default browser
while read line; do
am start -a android.intent.action.VIEW -d "$line" --activity-exclude-from-recents;
sleep 1;
done < $list
rm $list;
Prerequisites
Here are the hard prerequisites for the script to work:
- You must have root access1.
- Busybox must be installed and available under PATH variable.
Firefox Browser for Android is required. It is required because Chrome doesn't support tags, the bookmark folders are not visible through Chrome's content provider and it would be painful to me if I begin to parse Chrome's bookmarks file available in its private directory. I didn't test with other browsers so that's another reason why I made Firefox a prerequisite.
It is to be noted that you're not required to use Firefox browser as your daily driver, but only to make and keep bookmarks in it for them to be sorted through particular keywords. Firefox browser doesn't support multiple keywords for bookmakrs, as of v44.0.2.
To add a keyword: Bookmark a link in Firefox, go to Bookmarks tab, long press on your bookmark → Edit → add your keyword under Keyword.
I've not tested with a keyword containing a space so if the script doesn't work with a keyword containing space(s), replace space(s) with _ in your bookmarks and then try the script.
I've only tested this solution with Firefox and Chrome so I can't guarantee that this would work with any browser. However, common sense dictates that if it is a browser for casual browsing, it would have registered for an intent having a URL data type, so the browser should have no problem with my script.
Note: For some reason, Firefox couldn't handle the series of bookmarks after some time and crashed. (It actually crashed every time.) On the other hand, Chrome v45.0.2564.95 didn't crash even for once.
Here's how the script can be executed after saving it under /sdcard with extension .sh:
Running the script
Install a terminal emulator app and execute:
su -c 'sh /sdcard/FILE KEYWORD BROWSER'
Example:
su -c 'sh /sdcard/bms_launch.sh Stack_Exchange com.android.chrome' # this would launch all the bookmarks tagged with the keyword Stack_Exchange in the default browser com.android.chrome
Things to know:
- FILE: file name of the script, e.g.: bms_launch.sh
- KEYWORD: the keyword to which all associated bookmarks should be searched for and be launched in default browser
BROWSER: package name of your default browser. To know the package name, follow View app's full package name?
Note: it is not necessary to provide package name of the default browser. I used it because I had to force-stop Chrome as Chrome was causing some complication without a force-stop.
Convenient execution
How you would execute this script in your device is upon you to decide. I can recommend these two methods. Any of them would be enough.
1 Root access is needed because I don't know how to generate (and easily parse) a list of bookmarks from some browser dynamically. Even if I can have such a list, I wouldn't be able to go on unless I know that those bookmarks can be sorted using a tag or a keyword. This is why I chose Firefox and root access.
The dependency on a single keyword might cause inconvenience but I've given you a (possibly good) idea. If your preferred browser supports multiple tags/keywords for bookmarks then you should have no problem in tweaking my script per your needs.