forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslack-send-message.applescript
executable file
·106 lines (94 loc) · 2.97 KB
/
slack-send-message.applescript
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
96
97
98
99
100
101
102
103
104
105
106
#!/usr/bin/osascript
# Required parameters:
# @raycast.author Faris Aziz
# @raycast.authorURL https://github.com/farisaziz12
# @raycast.schemaVersion 1
# @raycast.title Send Message in Channel
# @raycast.mode silent
# @raycast.packageName Slack
# @raycast.description This script posts a message text to a slack channel and sets active status (defaults to random good morning message in #general)
# @raycast.needsConfirmation true
# @raycast.argument1 { "type": "text", "placeholder": "Channel (default: #general)", "optional": true, }
# @raycast.argument2 { "type": "text", "placeholder": "Message (default: good morning)", "optional": true, }
# @raycast.argument3 { "type": "text", "placeholder": "Set Active? y/n", "optional": true, }
# Optional parameters:
# @raycast.icon images/slack-logo.png
on openChannel(channel)
tell application "Slack"
activate
tell application "System Events"
keystroke "k" using {command down}
delay 0.5
keystroke channel
delay 0.5
key code 36
delay 0.5
end tell
end tell
end openChannel
on sendMessage(msg)
tell application "Slack"
activate
tell application "System Events"
keystroke msg
delay 0.5
key code 36
end tell
end tell
end sendMessage
on slashCommand(cmd)
tell application "Slack"
activate
tell application "System Events"
key code 44
delay 0.5
keystroke cmd
delay 0.5
key code 36
end tell
end tell
end slashCommand
on pressReturn()
tell application "Slack"
activate
tell application "System Events"
delay 1
key code 36
end tell
end tell
end pressReturn
on run argv
set channel to item 1 of argv
set message to item 2 of argv
set setActive to item 3 of argv
set today to do shell script "date +%A"
set todayText to "Happy " & today & "!"
set goodMorningTexts to {"Good Morning all!", "Good Morning Everyone!", todayText }
set randomItemNum to random number from 1 to count of goodMorningTexts
set randomGoodMorningText to item randomItemNum of goodMorningTexts as string
-- if no channel argument set #general as default
if channel = "" then
set channelToSendTo to "#general"
else
set channelToSendTo to channel
end if
-- if no message argument set random good morning message as default
if message = "" then
set messageToSend to randomGoodMorningText
else
set messageToSend to message
end if
openChannel(channelToSendTo)
-- setting to active will not work if already active
if setActive = "y" or setActive = "Y" then
sendMessage(messageToSend)
slashCommand("Set yourself as active")
pressReturn()
log messageToSend & " sent To " & channelToSendTo &" and status set to active!"
else if setActive = "n" or setActive = "N" or setActive = "" -- default is no
sendMessage(messageToSend)
log messageToSend & " sent To " & channelToSendTo &"!"
else
log "Invalid argument for set active. Specify setting active using 'y' or 'n'"
end if
end run