-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathalert
executable file
·80 lines (62 loc) · 2.32 KB
/
alert
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
#!/usr/bin/osascript
-- Provides shell level windowed alerting system.
-- returns true iff an app with the given name is running
on is_app_running(name)
tell application "System Events" to (name of processes) contains name
end is_app_running
-- raises an app with the given name if it's running
on raise_app(name)
if is_app_running(name) then
tell application name to activate
end if
end raise_app
on run argv
set quiet_flag to false
set ignore_flag to false
-- parse out flags
set params to {}
repeat with arg in argv
repeat 1 times -- inner loop to allow continuation of outer loop
set arg to arg as text
if not ignore_flag and arg = "--" then
set ignore_flag to true
exit repeat -- continue
end if
if not ignore_flag and arg = "-q" then
set quiet_flag to false
exit repeat -- continue
end if
if not ignore_flag and (arg = "-h" or arg = "--help") then
return "usage: alert [-qh] [message]
-h: print usage help
-q: enable quiet mode (do not generate any sound)"
end if
copy arg to end of params
end repeat
end repeat
-- convert params to message
set AppleScript's text item delimiters to " "
set message to params as string
-- report message to audio
if not quiet_flag and not message equal "" then
do shell script "say -- " & quoted form of message
end if
-- get currently active app
set calling_app to (path to frontmost application as text)
-- only show Dismiss button if Terminal isn't the current app
set dialog_buttons to {"OK"}
if calling_app as text doesn't contain "Term" then
set dialog_buttons to {"Dismiss"}
end if
-- rightmost button should always be default
set default_button to last item of dialog_buttons
-- default message (not spoken) if no message was given
if message equal "" then
set message to "process complete"
end if
-- create an alert dialog message
tell application "SystemUIServer" to display dialog message ¬
buttons dialog_buttons default button default_button with title "Alert" with icon stop
-- report message to terminal
return "alert: " & message
end run