samknight / slack_applescript Goto Github PK
View Code? Open in Web Editor NEWAppleScript bundle for Slack methods
AppleScript bundle for Slack methods
Hello guys,
Hope you are doing all great.
I can't get the two commands to work: "set as away" and "set as active". When I run them, it sends messages in the conversation I'm in on Slack "= away" or "=active", depending on which command I run.
Here is my script:
tell script "Slack"
set as active
end tell
Thanks in advance and wish you all a great weekend ahead!
tell application "System Events"
set visible of application process "Slack" to false
end tell
Sending a message in the above context seems to make Slack visible again. Can this be avoided?
The new "Shortcuts" functionality that's rolling out to orgs now appears to break this.
When sending a command through "Slack" now, it just sends to the channel because the "Shortcuts" are removing the slash functionality and moving them to their own menu.
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.
Sorry, this is more a feature request, I'm looking for a way to listen for new message using AppleScript.
(the goal would be to auto reply the person or forward the message to iMessage for example)
-- sorry again to be out of topic
Hi,
I'm having issues setting the "do not disturb" mode.
When running:
tell script "Slack"
focus workspace "myWorkspace"
set do not disturb
end tell
I get the error: Can’t make «script "Slack"» into type Unicode text.
When running
tell script "Slack"
focus workspace "myWorkspace"
set do not disturb until 5pm
end tell
I get the error: Expected end of line, etc. but found “until”.
Am I doing something wrong or the commands are not working?
Thanks!
Hello -- thanks for this amazing Applescript!
Occasionally, it seems that Slack malforms the /status
command as /s. atus
which then results in an error:
10.15.7
Version 2.11 (208)
1.1.64.561.g71bd09eb-a
2.0.1 Fix
Here is my full Applescript:
repeat
if application "Spotify" is running then
tell application "Spotify"
set currentSong to (get artist of current track) & " – " & (get name of current track)
tell script "Slack"
set status currentSong with icon ":headphones:"
end tell
end tell
end if
delay 60
end repeat
However, if I close and restart Slack, the Apple script will work (just once). Subsequent attempts results in the malformed status.
Would appreciate your guidance here if you're able to shed some light, perhaps a mistake in my syntax -- thank you!
This Twitter thread https://twitter.com/pdancsok/status/1275831275249639425
eg. when I leave my cursor in a thread input the app tries the type there, but slack replies:
/open is not supported in threads. Sorry!
This would be pretty helpful
thanks
When I run
tell script "Slack"
focus channel "general"
end tell
it occasionally works (maybe 10% of the time) but usually it pastes "general" into whatever channel I'm currently in (and sends it!) When it does work I can tell it's exec'ing ⌘+K
then types the channel into the "Jump to" input. (This is a hack I was using that's been buggy for me, so I was hoping slack_applescript was a better solution.)
Also, when I'm on a call focus call window
does absolutely nothing, and the same with focus main window
. I gave up trying other commands.
Slack Version: 4.16.2
samknight/slack_applescript version: 2.0.1
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
Clearing the Status just prints out -Clear your status
on my current Slack window
I'm on BigSur 11.5.2 and Slack Version 4.19.0.
Thats what I've executed
osascript -e 'tell script "Slack"' -e 'clear status' -e 'end tell'
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?
thanks so much for this awesome project!
this is my first foray into AppleScript and I'd like to help add some functionality to this library; unfortunately, I can't figure out how you figured out the private dictionary / API for Slack.app
. Is this something you might be able to explain / point me in the right direction for discovering myself?
I've read a bit into the Script Editor dictionary / library docs and understand that these electron-based apps are a bit of a different animal than native apps, but I'm truly lost as to how you've reverse engineered any of this interface.
thanks again for this excellent project!
Is there a way to invoke the tell Slack script such that it does not bring slack to the front?
Hello, when I try to send a message of the style:
Super List:
The script print:
Super List: - Milk- Cereal- Beer
When trying to use / n / r
I get very strange things, for example:
/ r generates a message for each line instead of just one.
How could I manage to send everything together in one message?
After the latest Slack UI updates, the command "focus workspace 'Your Workspace'" returns this error:
error "System Events got an error: Can’t get menu item 1 of menu "Workspace" of menu item "Workspace" of menu "File" of menu bar item "File" of menu bar 1 of process "Slack" whose name starts with "Your Workspace". Invalid index." number -1719
Slack now has auto expiring statuses, would be cool to be able to set that up via this script, thanks for your hard work!
In Slack, under Preferences->Advanced->Input Options ...
When writing a message, press to ...
You can either choose "Send the Message", or "Start a new line (use Cmd Enter to send)"
This script expects the first option to be selected, and won't work if the second is.
First and foremost, I love that you've put this together. Great stuff @samknight — this is going to be super valuable for an automation I'm building.
Second, I'm getting an issue on Big Sur when I run the focus workspace
command:
From the error message, it looks like maybe it's expecting the workspace to be in the Window menu, however in my Slack app it's actually in File → Workspace → {Workspace Name}
.
Otherwise though, it's been smooth sailing. Thanks again for releasing this!
Hi,
I'd love to use this but why do you only have the compiled scpt file rather than the original source in the repo?
Thanks,
Tavis
When I set Slack to French or German and execute
tell application "Slack"
focus workspace "One Conversation"
end tell
I receive the error
System Events got an error: Can’t get menu bar item "File" of menu bar 1 of process "Slack".
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.
At the moment "set as away" is a toggle command. Executing it will toggle the status between active and away.
This can be tricky if you don't know what your current Slack status is. For example when you run the command from Alfred without Slack focused.
To me it would be more explicit if away would always set yourself as away, independent of what your current status is. For example by first settings yourself to active /active
(which is not a toggle command) and then to /away
.
Would be great to set status (like lunch) for a predefined amount of time, instead of having to provide end time.
I know your still working on the rewrite but here is some input on something I'll probably miss when using a QWERTY keyboard.
When I run this code:
tell script "Slack"
send message "this is an automated message" in channel "#testjeroen"
clear status
set as away
end tell
I get this on Slack:
this is an automated message
=Clear your status
=Set yourself as active
When I switch my keyboard layout to QWERTY it works better BUT the messages are not send (enter).
I don't have this folder ~/Library/Script Libraries
, and neither ~/Library/Scripting Libraries
. (Should I create them by the way?)
I then put the script to /Library/Scripts
, and tried
tell script "Slack"
set stauts "Lunch"
end tell
It told me Can't get script "Slack"
.
By the way, does your script support searching uses and open the DM window?
The installation instructions mentions unzipping a Slack.zip
which was removed in 46ae102.
Is there a new way to install it, or do we need to resurrect this file? 🙂
Hello, first, thank you very much for creating this!
Second, is there any way to add support for listing workspaces and channels?
Thanks again!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.