- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试编写一个脚本,该脚本将遍历消息应用程序中的所有聊天记录 - 我的目标是找到我尚未回复的所有消息并向我发送提醒。
但我被困在第一个 - 我可以看到我有多少消息:
tell application "Messages" to log (count of chats)
tell application "Messages" to set x to started of first chat
最佳答案
我用过你的 sqlite3
代码进行了一些小的调整,然后创建了这个 AppleScript,它会生成一个提醒列表(在提醒应用程序中)。唯一的缺点是发件人显示为电话号码或 iMessage 地址,并且不会使用您的地址簿“转换”为姓名。这可能可以通过一些 tell
来实现命令联系人并搜索电话号码,但目前这超出了这项特殊努力的范围。
-- Run an SQL query on the messages database via shell script
do shell script (["sqlite3 -line ~/Library/Messages/chat.db ", ¬
"'SELECT MAX(date) lastMessageDate, h.id, text ", ¬
"FROM message m INNER JOIN handle h ON h.ROWID=m.handle_id ", ¬
"WHERE is_from_me = 0 GROUP BY h.ROWID' | egrep -io -e '\\w+ = .+'"] as text)
set query_response to result
--> lastMessageDate = %timestamp%
--> id = %phone number or iMessage address%
--> text = %message content%
--> ...
-- Groups all messages into a single item of an array
-- Each occurence of "lastMessageDate = " indicates
-- a new message and, hence, a new array item.
set AppleScript's text item delimiters to "lastMessageDate = "
set query_response to rest of text items of query_response
-- Loop through the array organise each message
repeat with message in query_response
-- Split the array item up into its components
set [receivedOn, sentFrom, textContent] ¬
to [paragraph 1, ¬
text 6 thru -1 of paragraph 2, ¬
text 8 thru -1 of paragraph 3] of message
-- Convert ReceivedOn to a value representing
-- the number of days since 01/01/2001
set receivedOn to receivedOn / (1.0E+9 * 86400)
-- Convert ReceivedOn again to the date
-- corresponding to the number of days since
-- 01/01/2001, i.e. the date and time the message
-- was sent
set receivedOn to (date "Monday, 1 January 2001 at 00:00:00") + receivedOn * days
-- Make a reminder
tell application "Reminders"
if not (exists (list named "Awaiting My Reply")) then ¬
make new list with properties {name:"Awaiting My Reply"}
tell list named "Awaiting My Reply"
-- This creates a reminder with a past due date
-- meaning you can sort the reminder list by due
-- date to see who has been waiting longest
-- for you to reply
make new reminder with properties ¬
{name:"Reply To " & sentFrom, body:¬
textContent, due date:¬
receivedOn} ¬
end tell
end tell
end repeat
当然,如果您的任何文本消息碰巧包含短语“lastMessagedate =”,那么这将不适用于上面的脚本。但是,对此有一些解决方法,我尝试了
sqlite3
返回的各种格式。包括list、column、csv,各有优缺点。
-- Replace dbID with your address book's serial number
-- (look in ~/Library/Application Support/AddressBook/Sources)
property dbID : "377FDA5C-013A-430A-A964-9943C0B40137"
property db : {Messages:"/Users/CK/Library/Messages/chat.db", Addresses:"/Users/CK/Library/Application Support/AddressBook/Sources/" & dbID & "/AddressBook-v22.abcddb"}
-- Run an SQL query on the messages database via shell script
set Messages to do shell script (["sqlite3 -line ", ¬
quoted form of (Messages in db) as text, ¬
" 'SELECT MAX(date) lastMessageDate, h.id, text", ¬
" FROM message m INNER JOIN handle h ON h.ROWID=m.handle_id", ¬
" WHERE is_from_me = 0 GROUP BY h.ROWID'", ¬
" | egrep -io -e '\\w+ = .+'"] as text)
--> lastMessageDate = %timestamp%
--> id = %phone number or iMessage address%
--> text = %message content%
--> ...
set PhoneNumbers to do shell script (["sqlite3 -list -separator : ", ¬
quoted form of (Addresses in db) as text, ¬
" 'select r.ZFIRSTNAME, r.ZLASTNAME, p.ZFULLNUMBER", ¬
" from ZABCDRECORD as r, ZABCDPHONENUMBER as p", ¬
" WHERE p.ZOWNER=r.Z_PK'", ¬
" | tr -c -d '[:alnum:]:[:cntrl:]:[:space:]:+#*'"] as text)
--> %first name%:%last name:%phone number%
--> ...
set NamesAndNumbers to paragraphs of PhoneNumbers
set AppleScript's text item delimiters to ":"
tell NamesAndNumbers to ¬
repeat with n from 1 to count it
set its item n to ¬
{firstname:text item 1, lastname:text item 2, phone:text item 3} ¬
of its item n
end repeat
-- Groups all messages into a single item of an array
-- Each occurence of "lastMessageDate = " indicates
-- a new message and, hence, a new array item.
set AppleScript's text item delimiters to "lastMessageDate = "
set Messages to rest of text items of Messages
-- Loop through the array organise each message
repeat with message in Messages
-- Split the array item up into its components
set [receivedOn, sentFrom, textContent] ¬
to [paragraph 1, ¬
text 6 thru -1 of paragraph 2, ¬
text 8 thru -1 of paragraph 3] of message
-- Convert ReceivedOn to a value representing
-- the number of days since 01/01/2001
set receivedOn to receivedOn / (1.0E+9 * 86400)
-- Convert ReceivedOn again to the date
-- corresponding to the number of days since
-- 01/01/2001, i.e. the date and time the message
-- was sent
set receivedOn to (date "Monday, 1 January 2001 at 00:00:00") + receivedOn * days
-- Keep the "+" delimiter but replace the "+44" with
-- your own country's intl dialling code, e.g. {"+1", "+"}
-- as this may or may not prefix a phone number
set AppleScript's text item delimiters to {"+44", "+"}
set sentFrom to last text item of sentFrom
-- Find the name to whom the phone number belongs
ignoring white space
set match to ""
repeat with person in NamesAndNumbers
if the person's phone contains sentFrom then
set match to contents of the person
exit repeat
end if
end repeat
end ignoring
set AppleScript's text item delimiters to space
if match is not "" then set sentFrom to the contents of ¬
{firstname, lastname} of match as text
-- Make a reminder
tell application "Reminders"
if not (exists (list named "Awaiting My Reply")) then ¬
make new list with properties {name:"Awaiting My Reply"}
tell list named "Awaiting My Reply"
-- This creates a reminder with a past due date
-- meaning you can sort the reminder list by due
-- date to see who has been waiting longest
-- for you to reply
make new reminder with properties ¬
{name:"Reply To " & sentFrom, body:¬
textContent, due date:¬
receivedOn} ¬
end tell
end tell
end repeat
关于macos - 使用 AppleScript 阅读 iMessage,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48086287/
还有人在用applescript吗,苹果把文档存档了,好久没更新语言了。这是否意味着语言已死? 最佳答案 自从苹果在 2016 年解散 Mac 自动化团队并(迟迟)解雇了负责它的产品经理以来,整个 A
我无法弄清楚如何检测 AppleScript 中按下的键以及如何延迟直到该键被释放。我想切换缩放,我拥有其他一切(我认为)。这是我当前的代码 on idle set ztoggle to 0
是否可以为使用 AppleScript 创建的应用程序保存某种设置? 设置应在脚本开始时加载,并在脚本结束时保存。 例子: if loadSetting("timesRun") then se
我正在尝试显示我选择的文件的扩展名。我做错了什么? set theFile to (choose file with prompt "Select a file to transfer:")
我正在尝试制作一个将在后台运行并且每周只在特定时间执行一次的 applescript,有什么建议吗? 最佳答案 您可能想要的是 idle handler .首次打开 AppleScript 应用程序时
我希望能够引用与 Controller 位于同一目录中的模型文件。 最初,它们位于项目的根文件夹中,但当它们被编译(使用 osacompile)时,它们都将位于 Controller.scptd/Co
我不知道如何使用 AppleScript,一开始我是如何让我的小 bash 脚本工作的,这超出了我的能力。我目前正在使用 AppleScript 来运行我的 bash 脚本,它工作得非常好。它在下面。
我有一系列 AppleScript 命令需要在一行 AppleScript 中实现。代码如下。 delay 2 tell application "System Events" to keystrok
在 VBA 中,用不同的子字符串替换子字符串非常容易,例如 objMsg.Body = Replace(objMsg.Body, ""在电子邮件正文中使用当前月份。我以前见过与此类似的问题,但它们已经
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我已被任命创建一个必须 当网页加载完后,显示一个对话框,显示"The webpage has finished loading." 确定当前正在下载的项目数量 对于数字1,我尝试做if the U
我有一个用于创建作业文件夹的 Applescript。 Applescript 要求提供项目名称和文件夹的存储位置。输入作业名称和文件夹位置后,脚本会创建主文件夹和四个子文件夹。 现在我希望脚本在当前
我有一个字符串,其中包含要删除的非法字符,但我不知道可能存在哪种字符。 我建立了一个我不希望被过滤的字符列表,并建立了这个脚本(来自我在网络上找到的另一个脚本)。 on clean_string(Th
我很困惑 - 我已经用谷歌搜索了一个小时,并尝试了大约十种不同形式的 set posixDirectory to POSIX path of (parent of (path to aFile) as
我在 Automator 中有一个小的 applescript: do shell script "osascript ~/Focus-On.scpt" delay 60 do shell scrip
我想打开一个默认为应用程序设置文件夹的文件夹: /Users/XXX/Library/Application Support/Tunnelblick/Configurations 我不想“硬编码”“X
我试图找出最前面的应用程序 x 是什么,运行脚本,然后使用 applescript 将 x 设置为最前面的应用程序。 tell application "System Events" set
有一个 AppleScript 方法: on displayError(theErrorMessage) display dialog theErrorMessage return "
我正在尝试编写一个脚本来记录当前应用程序、切换到另一个应用程序、执行一些任务并返回到原始应用程序。这就是我所拥有的 set currentApp to my getCurrentApp() activ
我正在尝试根据其文本使用 AppleScript 选择大纲的特定行。 这是我正在考虑的(但不起作用): repeat with aRow in rows of outline 1 of scroll
我是一名优秀的程序员,十分优秀!