Scripts and Tricks
2023-09-24A collection of small scripts and tricks I’ve come across or wrote. Quite a lot of these intersect with my dotfiles.
Linux
Finding missing disk space
A long afternoon is spent cleaning up my disk. From 3GB free to 22GB free, a massive achievement! Then, I come back to my computer the next day, and find there to be only 16GB free. ‘Alright’ I say, let’s remove ~/.cache
. Still only 16GB free. Where did the other 6 go?!
Now, from time to time I run du
and save its output in a file. Whenever I want to compare the files and disk space taken up by those files, I use either diff
or comm
to compare the current snapshot to the previous.
# Take two snapshots some time apart
cd ~/documents
du > du_19-06-2023.txt
cd ~/documents
du > du_24-09-2023.txt
# Compare the lines either using diff or comm
# Using diff
diff -y du_19-06-2023.txt du_24-09-2023.txt --suppress-common-lines
# Using comm
sort du_19-06-2023.txt > /tmp/a.txt
sort du_24-09-2023.txt > /tmp/b.txt
comm /tmp/a.txt /tmp/b.txt -31
Application menu item for creating a new launcher.
I often find myself needing to create new .desktop
files, or “Launchers” or “Shortcuts” as they are more commonly called. After a while, opening my file manager and navigating to ~/.local/share/applications
, duplicating a file, renaming it, and tweaking the title, description, and launch options became tedious. That is, until one day, I stumbled onto XFCE’s exo-desktop-item-edit [Xfce Docs]. It’s a simple gui for editing .desktop
files, and can be passed a few arguments so that it creates a new file in ~/.local/share/applications
for you, with the options you fill out.
First, install XFCE’s exo-desktop-item-edit
.
Then, paste the below code block into ~/.local/share/applications/new_desktop_file.desktop
, making sure to replace user
with your username:
[Desktop Entry]
Version=1.0
Type=Application
Name=Create new launcher
Comment=Creates a new .desktop file in ~/.local/share/applications
Exec=exo-desktop-item-edit -c /home/user/.local/share/applications
Icon=caffeine
Path=
Terminal=false
StartupNotify=false
Now, next time, when you need to create a new launcher, you can just search for “Create new launcher” in your applications list, instead of copying an existing launcher from ~/.local/share/applications
, renaming it, and changing the paths to commands and icons.
Scripts
chafa-view.sh
Makeshift command-line image viewer making use of chafa.
deviceToggle.sh, deviceToggleSway.sh
Scripts for toggling the enabled/disabled status of a device.
deviceToggle.sh
is for Xorg, whereasdeviceToggleSway.sh
is for sway.
dunst-clock.sh
On-screen clock making use of dunst notifications
lockscreen.sh
My swaylock lockscreen script
lutris-checker.sh
Script for checking missing games in lutris, which is more thorough than lutris’ in-built checks.
newerThan.sh
Find all files newer than a certain date, useful for finding configuration files for programs, or save files for games
notify-blink.sh
Script for notifying that something happened (eg. screen recording started or screenshot taken) by changing the backlight level instead of using system notifications
rename-newest.sh
Renames newest file in a directory to name provided
timer.sh
Simple timer script which displays the time decreasing, unlike
sleep
.
xocr.sh, screen_ocr.sh
Scripts to grab text from a screen area using tesseract and
grimshot
(for sway) andxfce4-screenshooter
(for Xorg)
kill-focused-window.sh
Script for sway to kill process of focused window
virt-screen-for-window.sh
Script for sway to magnify a window by:
- Take dimensions of current window
- Create virtual screen with window dimensions
- Move window onto new virtual screen, and fullscreen it
- Run
wl-mirror
to mirror the output of the window
windows
Disable “smart” screen
Registry file to disable “smart” screen. Once downloaded, right click and “Import”
Password for Administrator prompt
Registry file that changes the administrator prompt to ask for a username and password, instead of a basic Yes/No.