#+TITLE: Scripts :DRAWER: #+STARTUP: overview #+LANGUAGE: en #+EMAIL: dehaeze.thomas@gmail.com #+AUTHOR: Dehaeze Thomas #+HTML_LINK_HOME: ./index.html #+HTML_LINK_UP: ./index.html #+HTML_HEAD: #+HTML_HEAD: #+HTML_HEAD: #+HTML_HEAD: #+HTML_HEAD: #+HTML_HEAD: :END: * Wallpapers :PROPERTIES: :header-args: :tangle ~/scripts/wallpapers.sh :header-args+: :comments both :mkdirp yes :header-args+: :shebang "#!/usr/bin/env bash" :END: #+begin_src bash while true; do nitrogen --set-zoom-fill --random ".wallpapers" sleep 10m done #+end_src * LockScreen :PROPERTIES: :header-args: :tangle ~/scripts/lockscreen.sh :header-args+: :comments both :mkdirp yes :header-args+: :shebang "#!/usr/bin/env bash" :END: First, turn off dunst #+begin_src bash killall -SIGUSR1 dunst && echo "off" > /tmp/dunststatus; #+end_src Turn off the music if it is playing. #+begin_src bash MPC_STATE=$(mpc | sed -n '2p' | cut -d "[" -f2 | cut -d "]" -f1) if [[ $MPC_STATE == "playing" ]]; then mpc pause fi #+end_src Then take a screenshot and process it. #+begin_src bash temp_file="/tmp/screen.png" rm -f $temp_file maim $temp_file convert $temp_file -scale 10% -scale 1000% $temp_file #+end_src Finally, lock the screen using =i3lock=. #+begin_src bash i3lock --no-unlock-indicator --ignore-empty-password --nofork --image=$temp_file && killall -SIGUSR2 dunst && echo "on" > /tmp/dunststatus #+end_src #+begin_src bash :tangle no revert() { xset dpms 0 0 0 } trap revert HUP INT TERM # turn off screen after 5 seconds xset +dpms dpms 5 5 5 # Parameters temp_file="/tmp/screen.png" icon="$HOME/Pictures/Evil_Rick_Sprite.png" width=1920 height=1080 blur_factor=6 lock_blur_factor=0 # Take the screen shot, blur the image and add the icon ffmpeg -f x11grab -video_size "${width}x${height}" -y -i $DISPLAY -i $icon -filter_complex "boxblur=$blur_factor:$blur_factor,overlay=(main_w-overlay_w)/2:(main_h-overlay_h)/2,boxblur=$lock_blur_factor:$lock_blur_factor" -vframes 1 $temp_file # Alternative # maim -d 1 $temp_file # convert -blur 0x8 $temp_file $temp_file # convert -composite $temp_file $icon -gravity South -geometry -20x1200 $temp_file # Lock the screen with the image i3lock --no-unlock-indicator --ignore-empty-password --show-failed-attempts --nofork --image=$temp_file # Remove the screenshot rm $temp_file # Don't turn off screen when back from lock revert #+end_src * Lock / Exit / Suspend / ... :PROPERTIES: :header-args: :tangle ~/scripts/quit.sh :header-args+: :comments both :mkdirp yes :header-args+: :shebang "#!/usr/bin/env bash" :END: #+begin_src bash option=$(echo -e "Lock\nExit\nLogout\nSuspend\nHibernate\nReboot\nShutdown" | rofi -i -dmenu) case "$option" in "Lock") i3exit lock ;; "Exit") i3exit switch_user ;; "Logout") i3exit logout ;; "Suspend") i3exit suspend ;; "Hibernate") i3exit hibernate ;; "Reboot") i3exit reboot ;; "Shutdown") i3exit shutdown ;; esac #+end_src * NAS - Mount :PROPERTIES: :header-args: :tangle ~/scripts/nas.sh :header-args+: :comments both :mkdirp yes :header-args+: :shebang "#!/usr/bin/env bash" :END: #+begin_src bash if [ $1 == "mount" ]; then if sudo -A mount 192.168.1.2:/volume1/Downloads/ /mnt/NAS/; then dunstify --replace=58249 'NAS' 'Successfully mounted' else dunstify --replace=58249 'NAS' 'Error while mounted' fi elif [ $1 == "umount" ]; then if sudo -A umount /mnt/NAS/; then dunstify --replace=58249 'NAS' 'Successfully unmounted' else dunstify --replace=58249 'NAS' 'Error while unmounted' fi fi #+end_src * Icons Unicode :PROPERTIES: :header-args: :tangle ~/scripts/icons.sh :header-args+: :comments both :mkdirp yes :header-args+: :shebang "#!/usr/bin/env bash" :END: #+begin_src bash # The famous "get a menu of emojis to copy" script. # Must have xclip installed to even show menu. xclip -h 2>/dev/null || exit 1 chosen=$(cut -d ';' -f1 ~/.local/share/emoji | rofi -dmenu -i -l 20 | sed "s/ .*//") [ "$chosen" != "" ] || exit # If you run this command with an argument, it will automatically insert the character. if [ -n "$1" ]; then xdotool key Shift+Insert else echo "$chosen" | tr -d '\n' | xsel -ib notify-send "'$chosen' copied to clipboard." & fi #+end_src * Org-Protocol-Capture-HTML :PROPERTIES: :header-args: :tangle ~/scripts/org-protocol-capture-html.sh :header-args+: :comments both :mkdirp yes :header-args+: :shebang "#!/usr/bin/env bash" :END: Defaults #+begin_src bash heading="link" template="pu" url="https://google.com/" #+end_src Functions #+begin_src bash function debug { if [[ -n $debug ]] then function debug { echo "DEBUG: $@" >&2 } debug "$@" else function debug { true } fi } function die { echo "$@" >&2 exit 1 } function urlencode { python -c " from __future__ import print_function try: from urllib import quote # Python 2 except ImportError: from urllib.parse import quote # Python 3 import sys print(quote(sys.stdin.read()[:-1], safe=''))" } #+end_src Documentation #+begin_src bash function usage { cat </dev/null 2>&1 & echo "Done" #+end_src