Skip to content

Instantly share code, notes, and snippets.

@hmble
Last active July 14, 2021 09:31
Show Gist options
  • Save hmble/ce73e4c94e251d7620f5526928345340 to your computer and use it in GitHub Desktop.
Save hmble/ce73e4c94e251d7620f5526928345340 to your computer and use it in GitHub Desktop.
Track clipboard and save the clipboard content to a file
#!/usr/bin/env bash
# Change file location to your preferred path
filelocation="$HOME/Notes/bookamarks.txt"
# Thanks to https://stackoverflow.com/a/3184819
regex='^(https?|ftp|file)://[-A-Za-z0-9\+&@#/%?=~_|!:,.;]*[-A-Za-z0-9\+&@#/%=~_|]$'
while clipnotify; do
text=$(xclip -o)
if [[ $(xclip -o) ]];then
if [[ $text =~ $regex ]];then
xclip -o >> $filelocation
echo "" >> $filelocation
fi
fi
done
@hmble
Copy link
Author

hmble commented Jul 14, 2021

My main gola for this is to only save the copied urls to a file so that I can later bulk import the bookmarks.

Prerequisite:
clipnotify

TODO:

  • Make a systemd file maybe to always run after login
  • Maybe save only the unique urls
  • timestamp the files

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