samknight/slack_applescript

Away command clashes with similar hubspot command

dennisnewel opened this issue · 0 comments

The current "set away" command effectively enters "/away" and hits enter. The issue I had was that on my work instance, another command had the name "away" in it, and it was listed higher in the popup for slack commands, which mean it would get picked instead of the built-in "/away" command.

I fixed it by adding a space before hitting enter, as that would get rid of the popup with the other option. The resulting "shortcut" function looks like this:

on shortcut(cmd, msg)
	tell application "Slack"
		activate
		tell application "System Events"
			keystroke "/"
			delay 0.5
			keystroke cmd
			delay 0.5
			if (cmd is equal to "away" or cmd is equal to "active") then
				key code 49
				delay 0.5
				key code 36 using {command down}
			else
				key code 36 using {command down}
			end if
			if (msg is not equal to "") then
				key code 49
				delay 0.5
				keystroke msg
				delay 0.5
				key code 36 using {command down}
			end if
		end tell
	end tell
end shortcut

On another note, "set do not disturb" i.e. shortcut("Pause all your notifications","") didn't work at all for me; it would just leave the text in input field. "set do not disturb for 25 minutes" did work though