Skip to content

Instantly share code, notes, and snippets.

@yugaego
Forked from Coool/automator_setup.md
Created November 3, 2024 22:53
Show Gist options
  • Save yugaego/282c287e56a2fee775c22919ed438075 to your computer and use it in GitHub Desktop.
Save yugaego/282c287e56a2fee775c22919ed438075 to your computer and use it in GitHub Desktop.
Clearing Telegram cache & Automate using LaunchDaemons and Automator application

How to setup clear cache on login.

Note: If your mac is off, LaunchDaemons will not run. So, automator will clear the cache during login.

  1. Open Automator application -> select Application -> Click Choose

application

  1. Select run shell script -> copy & paste clear_telegram_cache.sh -> Click test run

script_test

shell_script

  1. Provide a name for the application

save_application

  1. Open System Preferences -> Search for Login Items -> Add your application

login_item

add_login_item

<!-- Created using http://launched.zerowidth.com -->
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.zerowidth.launched.clear_telegram</string>
<key>ProgramArguments</key>
<array>
<string>sh</string>
<string>-c</string>
<!-- Update your script path here -->
<!-- NOTE: $HOME/script.sh did not work -->
<string>/Users/mags/clear_telegram.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<!-- Runs at 9.30 everyday -->
<key>Hour</key>
<integer>9</integer>
<key>Minute</key>
<integer>30</integer>
</dict>
</dict>
</plist>
<!--
Installing plist.
- mkdir -p ~/Library/LaunchAgents
- copy this file and paste it in ~/Library/LaunchAgents/clear_telegram.plist
- launchctl load -w ~/Library/LaunchAgents/clear_telegram.plist
- To verify this launchdaemons $ launchctl list | grep "telegram"
status should be 1, if 127 (script file not found) and if 0 (error in your plist)
-->
#!/bin/bash
set -e
telegramfolder=$(find ~/Library/Group\ Containers -type d -maxdepth 1 -name "*.keepcoder.Telegram")
telegramaccountfolder=$(find "${telegramfolder}" -type d -maxdepth 1 -name "account-*")
if [ -d "${telegramaccountfolder}" ]; then
echo "No such file or directory"
else
rm -r "${telegramaccountfolder}/postbox/media"
echo "Deleted telegram cache"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment