samknight / slack_applescript

AppleScript bundle for Slack methods
274 stars 19 forks source link

clear message box or warn before entering commands #32

Closed jonblatho closed 1 year ago

jonblatho commented 2 years ago

I'm not sure if this is even possible, but can a check be added to ensure that the message box is empty before attempting to enter a command, or could I be warned if it's not empty? I use this to simultaneously set myself as away/available on Slack and another application, and if I happen to have a message typed in the message box in Slack, this will send what I had typed with the command appended, like:

Lorem ipsu/Set yourself as away

...which can be a bit embarrassing, particularly when the typed "message" happens to be just a space.

Anyway, it's a nice-to-have, not a need-to-have, for my forgetful moments. Thanks for this though, very nice being able to use AppleScript for this! I'm very inexperienced with AppleScript but would be happy to help out if there's anything I can do.

henriquenunez commented 2 years ago

Hahah yeah I have the same issues.

I made a script that sets the status as the spotify song I'm listening to.... and you can imagine the mess

So I think I will try to do this improvement. I think that apple script may have some feature to help us do it.

(in the very moment I was typing rn it did that hahaha lol)

henriquenunez commented 2 years ago

Okay, just found out that the cmd + shift + y keystroke does the job for setting the status specifically

Imma try to change that

samknight commented 2 years ago

Hi both, ensuring the message box is focused has been a big headache for me, ensuring it's empty as well adds an extra layer of complication. Would either of you run an experiment for me? Could you add these commands above the slack commands? - this essentially selects all and deletes within the slack application

tell application "Slack"
  activate
  keystroke "a" using command down
  delay 0.5
  key code 51
end tell
henriquenunez commented 2 years ago

Hello, I could just run it now. It does not really function properly. Another thing is that we need to call "System Events" to send key code and keystroke commands. So my quick fix was:

tell application "Slack"
    activate
    tell application "System Events"
        tell process "Slack" to keystroke "a" using command down
        tell process "Slack" to key code 51
    end tell
    delay 0.5
end tell

When I run it and I am inside a chat, with the checkbox selected, it selects whatever is inside the message box. But in many other cases, like if I am just scrolling messages, it selects all the visible chat. (Let'sn't forget that slack uses electron) We could try to force that the message box is selected maybe...

Another thing is: is there any possibility to prevent a desktop switch? It is super annoying to call this script via another automation tool (I use hammerspoon to do some weird behaviour that will set my slack status as the song I am listening to on spotify, I know it's unprofessional but lol) And whenever the song switches the desktop switches and it's annoying and a mess and my only dream was to have a discord like feature so i can show off my music... anyway)

At the time of writing I maybe came up with a solution:

What y'all think?

samknight commented 2 years ago

This seems to get things close but doesn't work if you're focused on a thread. Also cmd+a works for me once I've used /

We could add that but with the caveat that this won't work for the main channel whilst your are in a thread

As for the desktop switch, due to electron app and non-first party support for these kind of scripts I don't think this will ever be possible. Very happy to be proven wrong though.

henriquenunez commented 1 year ago

Ok I just found out that you can exit the thread with option + up/down, which will also move you from the current channel.

As for the desktop switch, due to electron app and non-first party support for these kind of scripts I don't think this will ever be possible. Very happy to be proven wrong though.

I am going to take a deeper look if there is any additional tool we can use to achieve that.

samknight commented 1 year ago

I think I have found a combination that works.

arrow up
arrow left
arrow down
samknight commented 1 year ago

Hi all. I've gone with a different approach using the functions outlined in the 2.1.0 release

https://github.com/samknight/slack_applescript/releases/tag/2.1.0