Created
November 8, 2023 21:13
-
-
Save Shuna322/6c5d2af253cce5ecf1b187ec0ff6b579 to your computer and use it in GitHub Desktop.
Script to control the opacity of the applications window for the blur-my-shell extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This script is used to control the opacity of the applications window for the blur-my-shell extension | |
# Opacity can be controled with a dconf key at location /org/gnome/shell/extensions/blur-my-shell/applications/opacity | |
# The value of the key is a integer between 25 and 255 | |
# To change value the dconf write /org/gnome/shell/extensions/blur-my-shell/applications/opacity $value can be used | |
# The first argument of the script defines the action decrease or increase | |
# Opacity should be changed in the interval defined by the user from second optional argument | |
# If second argument is not provided the default value is 5 | |
# Pseudo code | |
# Get the current value of the opacity | |
# If the argument is not decrease or increase | |
# Print the usage of the script | |
# If the argument is decrease | |
# Decrease the value by 5 | |
# If the value is less than 25 | |
# Set the value to 25 | |
# If the argument is increase | |
# Increase the value by 5 | |
# If the value is greater than 255 | |
# Set the value to 255 | |
# If new value is the same as the old value | |
# Exit the script | |
# Set the value to the dconf key | |
# Function to print the usage of the script | |
usage() { | |
echo "Usage: $0 [decrease|increase] [interval]" | |
echo "interval: integer between 1 and 50" | |
exit 1 | |
} | |
# Set default value for the interval | |
interval=5 | |
# If the number of arguments is greater than 2 | |
if [ $# -gt 2 ]; then | |
# Print the usage of the script | |
usage | |
fi | |
# If the number of arguments is 2 | |
if [ $# -eq 2 ]; then | |
# If the second argument is not a number | |
if ! [[ $2 =~ ^[0-9]+$ ]]; then | |
# Print log message | |
echo "The interval should be a number" | |
# Print the usage of the script | |
usage | |
fi | |
# If the second argument is less than 1 | |
if [ $2 -lt 1 ]; then | |
# Print log message | |
echo "The interval should be greater than 0" | |
# Print the usage of the script | |
usage | |
fi | |
# If the second argument is greater than 50 | |
if [ $2 -gt 50 ]; then | |
# Print log message | |
echo "Maximum interval value is 50" | |
# Print the usage of the script | |
usage | |
fi | |
# Set the interval to the second argument | |
interval=$2 | |
fi | |
# If the first argument is not decrease or increase | |
if [ $1 != "decrease" ] && [ $1 != "increase" ]; then | |
# Print the usage of the script | |
usage | |
fi | |
# Get the current value of the opacity | |
current_opacity=$(dconf read /org/gnome/shell/extensions/blur-my-shell/applications/opacity) | |
new_opacity=$current_opacity | |
# If the argument is decrease | |
if [ $1 == "decrease" ]; then | |
# Decrease the value by the interval | |
new_opacity=$(($current_opacity - $interval)) | |
# If the value is less than 25 | |
if [ $new_opacity -lt 25 ]; then | |
# Set the value to 25 | |
new_opacity=25 | |
fi | |
fi | |
# If the argument is increase | |
if [ $1 == "increase" ]; then | |
# Increase the value by the interval | |
new_opacity=$(($current_opacity + $interval)) | |
# If the value is greater than 255 | |
if [ $new_opacity -gt 255 ]; then | |
# Set the value to 255 | |
new_opacity=255 | |
fi | |
fi | |
# If new value is the same as the old value | |
if [ $new_opacity -eq $current_opacity ]; then | |
# Print log message | |
echo "Opacity value didn't change" | |
# Exit the script | |
exit 0 | |
fi | |
# Set the value to the dconf key | |
dconf write /org/gnome/shell/extensions/blur-my-shell/applications/opacity $new_opacity | |
# Check if command was successful | |
if [ $? -eq 0 ]; then | |
# Print log message | |
echo "Opacity changed to $new_opacity" | |
exit 0 | |
else | |
# Print log message | |
echo "Failed to change opacity" | |
exit $? | |
fi |
Small demo:
blur-my-shell-opacity.demo.mp4
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A quick comment on why I made this script. I enjoy the looks of semi-transparent windows, but during screen demonstrations or recordings I need to keep my windows crisp since video compression would ruin the quality and the text will become unreadable. Doing this manually is a bit of a hassle so I made this script and binded it to the keyboard shortcut to make my life easier.