samknight / slack_applescript

AppleScript bundle for Slack methods
275 stars 20 forks source link

Not a valide command #33

Open MrDesjardins opened 2 years ago

MrDesjardins commented 2 years ago

Hello,

Running the following AppleScript:

tell script "Slack"
    set status "working"
end tell

I see Slack coming up and executing the / but at some point it fails with the following Slackbot message:

/statusworking is not a valid command. In Slack, all messages that start with the "/" character are interpreted as commands. If you are trying to send a message and not run a command, try preceding the "/" with an empty space.

I see in the Events window:

tell application "Slack"
    activate
end tell
tell application "System Events"
    keystroke "/"
    keystroke "status working"
    key code 36
    key code 36
end tell

I am running the script with the ScriptEditor on macOS Monterey 12.1

Thanks for script, and let me know if there is something I am not using properly.

MrDesjardins commented 2 years ago

For people having the same issue, instead of using the slack applescript library, I wrote an AppleScript that performs mostly what this library is trying to perform. It's my first AppleScript so, might not be the best code (got an issue with space that I fixed by explicitly sending 49 but it works.

tell application "Slack"
    activate
end tell

tell application "System Events"
    keystroke "/"
    keystroke "update"
    key code 49
    keystroke "your"
    key code 49
    keystroke "status"
    delay 1
    key code 76
    delay 1
    set textBuffer to "Hello world!"
    repeat with i from 1 to count characters of textBuffer
        if character i of textBuffer = " " then
            key code 49
        else
            keystroke (character i of textBuffer)
        end if
        delay 0.05
    end repeat
    delay 0.1
    key code 76
end tell
samknight commented 2 years ago

Thanks for assisting others @MrDesjardins

What do you think is causing the issue from my library - I've assumed in the past it's a timing issue