forked from raycast/script-commands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopycode.sh
executable file
·36 lines (26 loc) · 1 KB
/
copycode.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Copy Code
# @raycast.mode silent
# @raycast.packageName Messages
# Optional parameters:
# @raycast.icon images/Message.png
# Documentation:
# @raycast.description Copy verification code from a message.
# @raycast.author Fatpandac
# @raycast.authorURL https://github.com/Fatpandac
USERNAME=$(id -u -n)
result=$(sqlite3 /Users/$USERNAME/Library/Messages/chat.db 'SELECT text FROM message WHERE datetime(date/1000000000 + 978307200,"unixepoch","localtime") > datetime("now","localtime","-60 second") ORDER BY date DESC LIMIT 1;')
#You can append another `keyword` into the list to support other language Messages.
keyword=("验证码" "code");
keyword_regex="^(.*)(${keyword[*]/%/|})(.*)$"
if [ ! $result ]; then
echo "No verification code received in the last 60 seconds!"
exit 0;
fi
if [[ "$result" =~ "$keyword_regex" ]]; then
code=`echo $result | grep -o "[0-9]\{4,6\}"`;
echo "$code" | pbcopy;
echo "$code code copied!"
fi