我正在尝试从提醒应用程序中导出提醒数据。下面的脚本将执行此操作,但需要很长时间(第一次迭代花了 100 分钟,第二次迭代仍在运行(。
我已经读到发送AppleEvents(在这种情况下大约1000个(是扼杀性能的原因,但修复很少(我已经阅读过将脚本封装在script
,end script
和run script
中,但这似乎没有任何作用(。
我没有尝试过的一个有前途但乏味的途径是分别抓取所有十列,然后将它们paste
unix。
真正的问题当然是逐个查找表格的每个单元格。我怎样才能只抓取rs
中的所有对象(提醒(,包括它们的所有细节、按值,而不仅仅是一个引用列表?然后我可以随心所欲地解析它。
#!/usr/bin/osascript
set output to "Title,Notes,Completed,Completion Date,List,Creation Date,Due Date,Modification Date,Remind Me Date,Priorityn"
tell application "Reminders"
set rs to reminders in application "Reminders"
repeat with r in rs
set output to output & """ & name of r & "","" & body of r & "","" & completed of r & "","" & completion date of r & "","" & name of container of r & "","" & creation date of r & "","" & due date of r & "","" & modification date of r & "","" & remind me date of r & "","" & priority of r & ""n"
end repeat
end tell
return output
我晚了大约一年,但也许其他人会发现这个解决方案很有用。 诀窍是在变量rs
中存储对提醒的引用。 这样,AppleScript只需浏览一次每个提醒即可在repeat
循环中检索其属性。
use application "Reminders"
set text item delimiters of AppleScript to "|"
set output to {{"Title", "Notes", "Completed", "Completion Date", ¬
"List", "Creation Date", "Due Date", "Modification Date", ¬
"Remind Me Date", "Priority"} as text}
set rs to a reference to reminders
repeat with r in (a reference to reminders)
get {name, body, completed, completion date, ¬
name of container, creation date, due date, ¬
modification date, remind me date, priority} ¬
of r
set end of output to the result as text
end repeat
set text item delimiters of AppleScript to "n"
return output as text
或者,在定义变量rs
之后,可以像这样一次性获得所有提醒的所有属性:
set everything to the properties of rs
然后循环浏览此列表:
repeat with r in everything
(* same as above *)
.
.
.