Skip to content

Instantly share code, notes, and snippets.

@drbh
Created July 19, 2023 01:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drbh/71d575ddc5de9a548f0a7698b85b232c to your computer and use it in GitHub Desktop.
Save drbh/71d575ddc5de9a548f0a7698b85b232c to your computer and use it in GitHub Desktop.
smol apple script that sinks recent slack messages into a json file
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