Open rjmolina13 opened 2 days ago
@Covkie do you have the same issue on Linux?
@rjmolina13 can you upload the file before and after applying the patch?
What if you try
LC_CTYPE=C sed -i.bak 's/force-dark-mode/force-dark-nope/' "$path"
@JulienMaille Again, latest Spotify version for Mac. Before patch: Spotify_before.zip
After patch: Spotify_after.zip
Those are with my patch.
But with LC_CTYPE=C sed -i.bak 's/force-dark-mode/force-dark-nope/' "$path"
it now works!!
Now, auto theme switching between Light and Dark mode works! https://github.com/user-attachments/assets/656b7582-b351-4c43-8800-e070d4692311
Edit: So I think what happened is that changing the hex to 00's effectively damages the structure of the binary file. But with only replacing one word of the string the file structure is intact while altering the flag's functionality.
I might be wrong, but my thinking is: if the first patch;
sed -i.bak 's/force-dark-mode/\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/' "$path"
works on some versions, then the alternative patch;
LC_CTYPE=C sed -i.bak 's/force-dark-mode/force-dark-nope/' "$path"
should work on those versions where the first patch doesn’t.
Here I have updated the script to include both patches, with error handling and patching fallback. (Also added colors.) It tries the first patch then if errors out with illegal byte sequence it proceeds with the second patch.
I can make a PR to update the script in the repo if you want to.
https://gist.github.com/rjmolina13/4b46e5d0e8e4409bfc8aaff9c9cc4467
OR
#!/bin/bash
# discussion: https://github.com/JulienMaille/spicetify-dynamic-theme/issues/102
# script by:
# @Covkie
# @JulienMaille
# @rjmolina13
# Ensure Spicetify is in PATH
if ! command -v spicetify &> /dev/null; then
echo -e "\033[31mError: spicetify not found. Ensure it is installed and available in your PATH.\033[0m"
exit 1
fi
# Find where the Spotify binary is located
spotify_path=$(spicetify config spotify_path)
# Check for spicetify errors
if [[ $spotify_path == error* ]]; then
echo -e "\033[31mFailed to patch the file. $spotify_path\033[0m"
exit 1
fi
# Assemble the binary's path
if [[ "$OSTYPE" == "darwin"* ]]; then
_spotify_path=$(dirname "$spotify_path")
path="${_spotify_path}/MacOS/Spotify"
else
path="${spotify_path}/spotify"
fi
# Validate the path to ensure it exists and is a file
if [[ ! -f "$path" ]]; then
echo -e "\033[31mError: The Spotify binary was not found at the expected path: $path\033[0m"
exit 1
fi
# Attempt to patch the binary with null bytes, and fallback to alternative patch if needed
if ! sed -i.bak 's/force-dark-mode/\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00/' "$path"; then
echo -e "\033[31mEncountered illegal byte sequence. Attempting alternative patch.\033[0m"
echo ""
# Use alternative patch to replace 'force-dark-mode' with 'force-dark-nope'
if LC_CTYPE=C sed -i.bak 's/force-dark-mode/force-dark-nope/' "$path"; then
echo -e "\033[32mAlternative patch applied successfully.\033[0m"
else
echo -e "\033[31mFailed to apply alternative patch.\033[0m"
exit 1
fi
else
echo -e "\033[32mPrimary patch applied successfully.\033[0m"
fi
echo -e "\033[32mThe patch is complete. You may now restart Spotify.\033[0m"
Describe the bug Patching the Forced Dark Mode in Spotify via Theme's script doesn't work anymore even when tried to fix the script itself, results in Spotify not opening.
To Reproduce Steps to reproduce the behavior:
dmg
..sh
script..sh
script..plist
isn't being parsed properly.from
to
Screenshots
Desktop Setup
Logs