samknight / slack_applescript

AppleScript bundle for Slack methods

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unable to send message to a channel on first attempt

wabiloo opened this issue · comments

Hi,

I'm using your script to send a message to a slack channel from an Alfred Workflow.
I've moved to the latest version, following update of Slack to v4.10.3.

My script is simple:

set the_text to the clipboard
tell script "Slack"
	send message "whatis " & the_text in channel "@platform-bot" in workspace "Work"
end tell
return msg

This script is correctly opening Slack, switching workspace, opening the right channel, but then fails to paste and submit the message. If I try a second time, it works (but obviously it's already in the correct context).

Any idea?

Hi,

I believe we're seeing a few issues with the delay being too short. Whilst I keep working on the beta can I suggest you add in your own delay between moving channels and pasting the message.

tell script "Slack"
        focus workspace "Work"
        focus channel "@platform-bot" 
        delay 0.5
	send message "whatis " & the_text
end tell
return msg```

I've updated the library to 2.0.0.rc1 https://github.com/samknight/slack_applescript/releases/tag/2.0.0.rc1

please give this new version a try

Hi @samknight,
Sorry for the delay in getting back to you...

I'm afraid it's still not working for me.
I've update to 2.0.0, and also added the focus+delay snipped as above.


tell script "Slack"
	focus workspace "my_company"
	focus channel "@my_channel"
	delay 2
	send message "whatis " & the_text
end tell

I ran into 2 issue with this code:

  1. execution error: System Events got an error: Can’t get menu item 1 of menu "Window" of menu bar 1 of process "Slack" whose name starts with "my_company". Invalid index. (-1719)

  2. I then commented the focus workspace line. After that, the change of channel does occur, but the cursor is not in the message box and therefore the send message command doesn't do anything...

If I'm already on the correct channel when triggering the workflow, then for some reason the cursor is on the text box and the message does get sent (but that's defeating the point slightly)

One workaround is to repeat the focus channel line after the delay, but again, that's a little suboptimal.

Hi, I'm sorry this is not currently working for you.

  1. Please see my comment on the issue raised here #18
  2. Again sub optimal but you may wish to try
key code 44
delay 0.2
key code 53 

that should bring the text box into focus. Let me know if that works and I will add that in to the main library for release

Hi @wabiloo Did this work for you?

I have noticed that if you have the avatar menu up. You need to escape out of that and then do the above commands but you would automatically mark your current channel as read if that menu is not up.

How have you got on with this?

Closing due to inactivity but please feel to raise a new issue if you are still struggling