sms
https://spin.atomicobject.com/2020/05/22/search-imessage-sql/
import sqlite3
import os
import time
import re
import subprocess
conn = sqlite3.connect(os.environ['HOME'] + '/Library/Messages/chat.db')
cur = conn.cursor()
latest_rowid = None
while True:
cur.execute("select rowid, text from message order by date desc limit 1")
rowid, text = cur.fetchone()
if latest_rowid is None:
latest_rowid = rowid
if latest_rowid != rowid:
latest_rowid = rowid
numbers = re.findall(r'\d{4,6}', text)
if len(numbers) == 1:
number = numbers[0]
process = subprocess.Popen('pbcopy', env={'LANG': 'en_US.UTF-8'}, stdin=subprocess.PIPE)
process.communicate(number.encode('utf-8'))
subprocess.call([
"terminal-notifier",
"-group", "sms-code-to-clipboard",
"-title", "SMS 인증번호 클립보드에 복사됨",
"-message", f"인증번호 [{number}]가 클립보드에 복사되었습니다."],
)
time.sleep(0.1)