Skip to content

Instantly share code, notes, and snippets.

@cdracars
Created April 25, 2019 20:08
Show Gist options
  • Save cdracars/6ca1eb643d3dd1ef29bafa97a102b164 to your computer and use it in GitHub Desktop.
Save cdracars/6ca1eb643d3dd1ef29bafa97a102b164 to your computer and use it in GitHub Desktop.
MacOs Slack Dark Mode App/Script (You can Use appify[https://gist.github.com/mathiasbynens/674099] to turn this into an app)
#!/usr/bin/env bash
# If the file has already been modified don't try and modify it again
if grep -Fq "slack-night-mode" /Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/ssb-interop.js; then
/usr/bin/osascript <<EOA
tell app "System Events"
display notification "Dark Mode enabled previously.\rYou have made your choice to forsake the Light Mode." with title "Slack Dark Mode"
end tell
EOA
exit 0;
fi
# Append the dark mode patch to the file but request the users password so they have access ot modify the file
/usr/bin/osascript -e 'do shell script "
cat <<EOB >> /Applications/Slack.app/Contents/Resources/app.asar.unpacked/src/static/ssb-interop.js
document.addEventListener(\"DOMContentLoaded\", function() { [ruby-2.5.1p57]
let tt__customCss = \".menu ul li a:not(.inline_menu_link) {color: #fff }\"
$.ajax({
url: \"https://cdn.rawgit.com/laCour/slack-night-mode/master/css/raw/black.css\",
success: function(css) {
$(\"<style></style>\").appendTo(\"head\").html(css + tt__customCss);
}
});
});
EOB
# Success and error message handleing
if [[ $? -eq 0 ]]; then
/usr/bin/osascript <<EOC
tell app \"System Events\"
display notification \"Dark Mode enabled.\rWelcome to the Dark.\" with title \"Slack Dark Mode\"
end tell
EOC
else
/usr/bin/osascript <<EOD
tell app \"System Events\"
display dialog \"There was some trouble enabling Dark Mode.\" with title \"Slack Dark Mode\" buttons {\"Ok\"} default button 1 with icon caution
end tell
EOD
fi
# This is the magic part of the applescript to call the password dialog
" with prompt "Slack Dark Mode wants to make changes" with administrator privileges'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment