The original post: /r/datahoarder by /u/DonnerDinnerParty on 2025-02-05 19:27:58.
Here's an AppleScript that will walk a user through creating a scheduled task that will, during certain hours and days, write/overwrite a junk file once a minute.
It's in applsescript so you could run it without having to compile it as an application.
How to Use this
1. Open Script Editor (Applications > Utilities > Script Editor).
2. Paste the code below.
3. Click File > Save, choose Format: Application, and name it Install RAID Keeper.app.
4. Run the installer.
5. Choose your RAID folder and enter the active hours when prompted.
6. The script is installed and will automatically keep the RAID awake.
-- Prompt user for RAID location
set raidPath to POSIX path of (choose folder with prompt "Select your RAID drive or folder:")
-- Prompt user for active hours
display dialog "Enter the START hour for keeping the RAID awake (24-hour format)" default answer "9"
set startHour to text returned of result
display dialog "Enter the END hour for keeping the RAID awake (24-hour format)" default answer "17"
set endHour to text returned of result
set scriptContent to "
#!/bin/bash
RAID_PATH=\"" & raidPath & "\"
while true; do
DAY=$(date +%u) # 1=Monday, 7=Sunday
HOUR=$(date +%H) # 24-hour format
# Check if the current time is within the active range
if [[ \"$DAY\" -ge 3 && \"$DAY\" -le 7 ]] && [[ \"$HOUR\" -ge " & startHour & " && \"$HOUR\" -lt " & endHour & " ]]; then
dd if=/dev/urandom of=\"$RAID_PATH/.keepalive\" bs=1K count=1 status=none
sleep 60
else
sleep 300
fi
done
"
-- Define script installation path
set scriptPath to POSIX path of (path to library folder from user domain) & "Scripts/keep_raid_awake.sh"
-- Save the script to ~/Library/Scripts/
do shell script "mkdir -p ~/Library/Scripts/ && echo " & quoted form of scriptContent & " > " & quoted form of scriptPath
-- Set executable permissions
do shell script "chmod +x " & quoted form of scriptPath
-- Add to crontab for automatic startup
do shell script "crontab -l | { cat; echo '@reboot nohup " & scriptPath & " & disown'; } | crontab -"
-- Notify user
display dialog "Installation complete! The script is set up to keep your RAID awake from " & startHour & ":00 to " & endHour & ":00 (Wed-Sun). It will run on startup. If you want to start it now, restart your Mac or run the script manually." buttons {"OK"} default button "OK"
-- END