#+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:
#+PROPERTY: header-args:bash :comments both :mkdirp yes
#+PROPERTY: header-args:bash+ :shebang "#!/usr/bin/env bash"
:END:
* LockScreen
:PROPERTIES:
:header-args: :tangle ~/scripts/lockscreen.sh
: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
* TODO Lock / Exit / Suspend / ...
- [ ] Seems duplicated with [[file:binaries.org::*=i3exit= - Manage lock, suspend, reboot, ...][=i3exit= - Manage lock, suspend, reboot, ...]]
#+begin_src bash :tangle ~/scripts/quit.sh
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
* Download Torrent
#+begin_src bash :tangle ~/scripts/torrent-add.sh
transmission-remote ***REMOVED***:9091 --auth tdehaeze:$(pass nas/transmission | sed -n 1p) -a $1 && \
dunstify 'Torrent' 'Successfully added' || \
dunstify 'Torrent' 'Error'
#+end_src
* Org-Protocol-Capture-HTML
:PROPERTIES:
:header-args: :tangle ~/scripts/org-protocol-capture-html.sh
: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