-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsource.txt
95 lines (89 loc) · 2.51 KB
/
source.txt
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
### Controls ####
# on
# 5
# 2h
# off
# quit or end or exit or kill
# start or init
# no argument will toggle Caffeine on and off
################################
# On Indefinitely: caff on
# On for 5 Minutes: caff 5
# On for 2 Hours: caff 2h
# Off: caff off
# Quit App: caff quit or caff end or caff exit or caff kill
# Start App: caff start or caff init
# Toggle: caff
################################
# If you turn caffeine on and it's not started it will
# start automatically for you first. No need to call
# caff start first.
on sendMsg(msg)
tell application "System Events"
set isRunning to (count of (every process whose bundle identifier is "com.Growl.GrowlHelperApp")) > 0
end tell
if isRunning then
tell application id "com.Growl.GrowlHelperApp"
set the allNotificationsList to {"Caffeine Notification"}
set the enabledNotificationsList to {"Caffeine Notification"}
register as application "Caffeine Controls" all notifications allNotificationsList default notifications enabledNotificationsList icon of application "Caffeine"
notify with name "Caffeine Notification" title "Caffeine" description msg application name "Caffeine Controls" icon of application "Caffeine"
end tell
end if
end sendMsg
on alfred_script(q)
-- add hours-detection here
if q contains "h" then
set text item delimiters to "h"
set hours to text item 1 of q
if hours > 0 then
set q to (hours * 60)
end if
end if
-- original code below
set msg to ""
set s to {"start", "init"}
set e to {"quit", "kill", "end", "exit"}
tell application "Caffeine"
if q is in e then
set msg to "Bye Bye, see you next time."
quit
else if q is equal to "" or q is missing value or q is equal to "on" or q is equal to "off" then
if (active is false or q is equal to "on") and q is not equal to "off" then
set again to ""
if active is true then
set again to " again ;)"
end if
set msg to "Turned on indefinitely" & again
turn on
else
set again to ""
if active is false then
set again to " again ;)"
end if
set msg to "Turned off" & again
turn off
end if
else if q is in s then
set msg to "Application started"
activate
else
try
(q as real) div 1
turn on for (q * 60)
if q is equal to "1" then
set s to ""
else
set s to "s"
end if
set msg to "Turned on for " & q & " minute" & s
on error
set msg to "Turned on indefinitely"
turn on
end try
end if
end tell
if msg is not equal to "" then
sendMsg(msg)
end if
end alfred_script