Hi, I download a file weekly (I download it 1 week before it's shown at my church) using a shell script, but wondered how one might use Keyboard Maestro do this natively instead of a shell script?
Here is the script I use:
#!/bin/bash
Adjust the current date by adding 7 days
AdjustedDate=$(date -j -v+7d "+%Y-%m-%d")
Extract the year, month, and day from the adjusted date
Year=$(date -j -f "%Y-%m-%d" "$AdjustedDate" "+%y")
Month=$(date -j -f "%Y-%m-%d" "$AdjustedDate" "+%m")
DayOfYear=$(date -j -f "%Y-%m-%d" "$AdjustedDate" "+%j")
Calculate the quarter based on the month
Quarter=$(( (10#$Month - 1) / 3 + 1 ))
Calculate the start day of the current quarter
StartOfQuarter=$(( ($Quarter - 1) * 91 + 1 ))
Calculate the week of the quarter
WeekOfQuarter=$(( ($DayOfYear - $StartOfQuarter) / 7 + 1 ))
Ensure the week is valid
if [ $WeekOfQuarter -lt 1 ]; then
WeekOfQuarter=1
fi
Construct the URL
URL="https://cdns.adventistmission.org/MS/MS-${Year}${Quarter}-${WeekOfQuarter}-WEEKLY-EN.mp4"
Download location
DownloadLocation="$HOME/Downloads/MS-${Year}${Quarter}-${WeekOfQuarter}-WEEKLY-EN.mp4"
Download the file using curl
curl -o "$DownloadLocation" "$URL"
A typical url is: https://cdns.adventistmission.org/MS/MS-251-1-WEEKLY-EN.mp4
25 is the yr
1 (after the 25) is the quarter in the year
-1- is the week inside that quarter
Thought the use of variables might work ok, but wasn't sure if there was an easier method natively inside of Keyboard Maestro.
Thanks!