forked from brock/Reminders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.sh
64 lines (58 loc) · 1.81 KB
/
script.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/bash
# This script creates a "cronjob" using MacOSX's preferred "launchd"
# Convert minutes to seconds, then create a one-time cron that
# simply calls up a sticky growlnotify with your reminder.
if [[ $1 == "cleanup" ]]; then
echo "Cleaning up expired reminders..."
if launchctl list | grep com.approductive.remindersapp > /dev/null; then
ACTIVE_REMINDERS=(`launchctl list | grep com.approductive.remindersapp | awk '{print $3}'`)
REMINDER_PLISTS=(`ls ~/Library/LaunchAgents/com.approductive.remindersapp.*`)
for plist in "${REMINDER_PLISTS[@]}"
do
trimmed_plist=$(basename $plist | sed 's#.plist##g')
match=$(echo "${ACTIVE_REMINDERS[@]}" | grep -o "$trimmed_plist")
if [[ -z $match ]]; then
rm $plist
fi
done
fi
exit
fi
MINUTES=$1
TIMESTAMP=$(command date +%s)
TIMER=$(($1 * 60))
GROWL=/usr/local/bin/growlnotify
shift
REMINDER=$*
echo "$MINUTES minute reminder:"
echo "$REMINDER"
cat > ~/Library/LaunchAgents/com.approductive.remindersapp.$TIMESTAMP.plist <<EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.approductive.remindersapp.$TIMESTAMP</string>
<key>ProgramArguments</key>
<array>
<string>$GROWL</string>
<string>-s</string>
<string>--image</string>
<string>$HOME/Library/Application Support/Alfred/extensions/scripts/Reminders/reminders.png</string>
<string>-m</string>
<string>$REMINDER</string>
<string>-t</string>
<string>Reminders</string>
</array>
<key>StartInterval</key>
<integer>$TIMER</integer>
<key>RunAtLoad</key>
<false/>
<key>LaunchOnlyOnce</key>
<true/>
<key>OnDemand</key>
<true/>
</dict>
</plist>
EOF
launchctl load ~/Library/LaunchAgents/com.approductive.remindersapp.$TIMESTAMP.plist