# date: 29th Dec 2007
# usage: a simple python script to check for unread messages at interval
# if there are unread messages, play a user-defined sound
# warning: this script is not well tested, so use at your own risk
# the script requires Python and Erica's Utilities to work
# any problem please drop me a message
# contact: peeInMyPantz@gmail.com
import sqlite3
import os
import time
sms_db_path = "/private/var/root/Library/SMS/sms.db"
# sound file to play when there are unread messages
sound_path = "/private/var/root/Library/Scripts/sounds/OW1.WAV"
# interval for checking unread SMS (in seconds)
interval = 600
def main():
while 1:
time.sleep(interval)
if has_unread(sms_db_path):
playSound()
def has_unread(sms_db_path):
conn = sqlite3.connect(sms_db_path)
c = conn.cursor()
# check for unread messages
query = '''select count(flags) from message where flags=0'''
c.execute(query)
unread = int(c.fetchone()[0])
conn.close()
if unread>0:
return 1
else:
return 0
def playSound():
cmd = "playaudio %s" % sound_path
os.popen(cmd)
main()