Created
September 2, 2025 13:06
-
-
Save pepoluan/cb547b5b5eda2b59c491e878d45033fe to your computer and use it in GitHub Desktop.
Backup Daily Windows Lockscreen Wallpaper (for Cygwin)
This file contains hidden or 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
#!/usr/bin/env bash | |
# Requires: Cygwin | |
# | |
# SPDX-License-Identifier: MPL-2.0 | |
# | |
# This Source Code Form is subject to the terms of the Mozilla Public | |
# License, v. 2.0. If a copy of the MPL was not distributed with this | |
# file, You can obtain one at https://mozilla.org/MPL/2.0/. | |
# | |
# (C) 2025, Pandu POLUAN | |
##### EDITABLE SECTION ##### | |
DST_w="${USERPROFILE//\\/\\\\}"'\Pictures\Wallpapers' | |
##### DO NOT EDIT BELOW THIS LINE ##### | |
DST="$(cygpath "${DST_w//\\/\\\\}")" | |
SRC_w="${USERPROFILE//\\/\\\\}"'\AppData\Local\Packages\Microsoft.Windows.ContentDeliveryManager_cw5n1h2txyewy\LocalState\Assets' | |
SRC="$(cygpath "$SRC_w")" | |
# Regex to extract the dimensions of the pic from the output of the `file` command | |
_RE_RES=", ([0-9]+)x([0-9]+)" | |
echo "Source: $SRC" | |
echo "Dest : $DST" | |
mkdir -p "$DST" | |
cd "$SRC" | |
for f in *; do | |
FMETA="$(file -b "$f")" | |
# If not JPEG, skip | |
if [[ ${FMETA:0:4} != "JPEG" ]]; then | |
echo -n "." | |
continue | |
fi | |
# If already exists, skip | |
TARG="$DST"/"$f".jpeg | |
if [[ -e "$TARG" ]]; then | |
echo -n "!" | |
continue | |
fi | |
# Only copy landscape format | |
# WARNING: DO NOT enclose the vars here with quotes!! | |
if [[ $FMETA =~ $_RE_RES ]]; then | |
_w=${BASH_REMATCH[1]} | |
_h=${BASH_REMATCH[2]} | |
if (( _w > _h )); then | |
cp "$f" "$TARG" | |
echo -n "+" | |
else | |
echo -n "-" | |
fi | |
else | |
echo -n "?" | |
fi | |
done | |
echo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment