Created
July 19, 2023 01:08
-
-
Save drbh/71d575ddc5de9a548f0a7698b85b232c to your computer and use it in GitHub Desktop.
smol apple script that sinks recent slack messages into a json file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tell application "Safari" | |
-- Open Slack and navigate to the desired channel | |
activate | |
-- Navigate to the desired channel (with Josh in the name) | |
tell window 1 | |
set currentTab to tab 1 | |
set URL of currentTab to "https://app.slack.com/client/SPACE/CHAN" | |
repeat until (do JavaScript "document.readyState" in currentTab) is "complete" | |
delay 0.2 | |
end repeat | |
end tell | |
-- Console log a message to test that this is working | |
tell window 1 | |
delay 5 | |
do JavaScript "console.log('Hello from AppleScript!', Date.now());" in currentTab | |
end tell | |
-- Scroll to the bottom of the channel | |
tell window 1 | |
do JavaScript "window.scrollTo(0,document.body.scrollHeight);" in currentTab | |
end tell | |
-- Read the messages into a list | |
tell window 1 | |
set messageList to do JavaScript "var messageList = []; var messages = document.getElementsByClassName('c-message_kit__actions'); for (var i = 0; i < messages.length; i++) { messageList.push(messages[i].innerText.replace(/\\n/g, ' ')); } JSON.stringify(messageList);" in currentTab | |
end tell | |
-- Write the list to localhost 8080 as JSON | |
do shell script "echo '" & messageList & "' > ~/Desktop/messages.json" | |
end tell |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment