Applescript评测/效率:从应用程序导出对象列表和对象详细信息
我正在尝试从提醒应用程序导出提醒数据。下面的脚本将这样做,但需要很长时间(第一次迭代耗时100分钟,第二次迭代仍在运行) 我已经读过,发送appleevent(在本例中大约1000个)会降低性能,但修复很少(我读过关于在Applescript评测/效率:从应用程序导出对象列表和对象详细信息,applescript,Applescript,我正在尝试从提醒应用程序导出提醒数据。下面的脚本将这样做,但需要很长时间(第一次迭代耗时100分钟,第二次迭代仍在运行) 我已经读过,发送appleevent(在本例中大约1000个)会降低性能,但修复很少(我读过关于在脚本、结束脚本和运行脚本中封装脚本的内容,但这似乎没有任何作用) 我没有尝试过的一种有希望但乏味的方法是分别抓取所有十列,然后将它们粘贴在一起 当然,真正的问题是逐个查找表中的每个单元格。我怎样才能抓取rs中的所有对象(提醒)及其所有细节(按值),而不仅仅是参考列表?然后我可以随
脚本
、结束脚本
和运行脚本
中封装脚本的内容,但这似乎没有任何作用)
我没有尝试过的一种有希望但乏味的方法是分别抓取所有十列,然后将它们粘贴在一起
当然,真正的问题是逐个查找表中的每个单元格。我怎样才能抓取rs
中的所有对象(提醒)及其所有细节(按值),而不仅仅是参考列表?然后我可以随心所欲地解析它
#!/usr/bin/osascript
set output to "Title,Notes,Completed,Completion Date,List,Creation Date,Due Date,Modification Date,Remind Me Date,Priority\n"
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 *)
.
.
.