#!/bin/zsh

if [ -z $(launchctl list | grep com.filewave.slack_drive_space) ]
then
	# Set random time so everything does check in at the same time
	the_day=$(( 1 + RANDOM % 5 ))
	the_hour=$(( 9 + RANDOM % 9 ))
	the_minute=$((0 + RANDOM %59 ))

	/usr/libexec/PlistBuddy -c "Set :StartCalendarInterval:Weekday $the_day" /Library/LaunchDaemons/com.filewave.slack_drive_space.plist 
	/usr/libexec/PlistBuddy -c "Set :StartCalendarInterval:Hour $the_hour" /Library/LaunchDaemons/com.filewave.slack_drive_space.plist 
	/usr/libexec/PlistBuddy -c "Set :StartCalendarInterval:Minute $the_minute" /Library/LaunchDaemons/com.filewave.slack_drive_space.plist 

	launchctl load /Library/LaunchDaemons/com.filewave.slack_drive_space.plist
fi

exit 0
