Skip to content

Instantly share code, notes, and snippets.

@stnvh
Last active August 5, 2020 00:58
Show Gist options
  • Save stnvh/ffe5d2b51cb39a102568 to your computer and use it in GitHub Desktop.
Save stnvh/ffe5d2b51cb39a102568 to your computer and use it in GitHub Desktop.
Regularly wipe message history on OS X at configurable intervals — Uses applescript to completley remove conversations from app
#!/bin/bash
# removes various files related to stored iChat/Messages data on disk
# ran through launchd. relies on compiled applescript to fully remove all conversation traces
# will not run if the system is in use, unless the system has been idle for the amount of minutes below
TIMEOUT=15
## start ##
IDLE=$(echo $((`ioreg -c IOHIDSystem | sed -e '/HIDIdleTime/ !{ d' -e 't' -e '}' -e 's/.* = //g' -e 'q'` / 1000000000)))
SECONDS=$(($TIMEOUT * 60))
if [[ $SECONDS -gt $IDLE ]]; then
echo "skipping. idle for "$IDLE"s, timeout "$SECONDS"s"
exit
fi
killall -9 "Messages"
sleep 0.5
open "$HOME/Applications/Chatwipe.app" --wait-apps
rm -Rf "$HOME/Library/Messages/"
rm -Rf "$HOME/Library/Containers/com.apple.iChat/"
rm -f "$HOME/Library/Containers/com.apple.corerecents.recentsd/Data/Library/SyncedPreferences/recentsd-com.apple.messages.recents.plist"
rm -f "$HOME/Library/SyncedPreferences/recentsd-com.apple.messages.recents.plist"
find /var/folders -d -iname "com.apple.iChat" -exec rm -Rf {} \;
-- Save as an app via Script Editor, then add to the 'Accessibility' list in Security & Privacy
property currentFocus : ""
property buddyCount : 100
on focus()
tell application "System Events" to tell application process currentFocus to set frontmost to true
end focus
tell application "System Events"
set currentFocus to name of first application process whose frontmost is true -- store currently focused app name
tell application "Messages"
activate -- open the app
my focus() -- bring our original window to front
set buddyCount to (count of buddies) -- set our buddy count here, as we can't access it in the 'process' block
end tell
tell process "Messages"
set position of window 1 to {2048, 2048} -- move messages out the way
repeat buddyCount times
set frontmost to true -- set messages to front
click menu item "Delete Conversation" of menu 1 of menu bar item "File" of menu bar 1
my focus() -- bring our original window to front
delay 0.2
end repeat
end tell
tell application "Messages" to quit -- quit after removal
end tell
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>local.stnvh.chatwipe</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>~/bin/chatwipe</string>
</array>
<key>StartInterval</key>
<integer>300</integer>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment