Applescript 从地址簿备注字段中逐行获取Apple脚本
我在通讯簿的备注字段中有两行Applescript 从地址簿备注字段中逐行获取Apple脚本,applescript,automator,Applescript,Automator,我在通讯簿的备注字段中有两行 Test 1 Test 2 我希望将每一行作为单独的值获取,或者从notes字段获取最后一行 我试着这样做: tell application "Address Book" set AppleScript's text item delimiters to "space" get the note of person in group "Test Group" end tell 但结果是 {"Test 1 Test 2"} 我正在寻找: {"Test1",
Test 1
Test 2
我希望将每一行作为单独的值获取,或者从notes字段获取最后一行
我试着这样做:
tell application "Address Book"
set AppleScript's text item delimiters to "space"
get the note of person in group "Test Group"
end tell
但结果是
{"Test 1
Test 2"}
我正在寻找:
{"Test1","Test2"}
我做错了什么?您的代码有一些地方出错。首先,您从未实际请求注释的文本项:-)您只得到原始字符串。第二个是
将AppleScript的文本项分隔符设置为“space”
将文本项分隔符设置为文本字符串space
。因此,例如,运行
set AppleScript's text item delimiters to "space"
return text items of "THISspaceISspaceAspaceSTRING"
set AppleScript's text item delimiters to " "
return text items of "This is a string
which is on two lines."
return paragraphs of "This is a string
which is on two lines."
返回
{"THIS", "IS", "A", "STRING"}
{"This", "is", "a", "string
which", "is", "on", "two", "lines."}
其次,即使您使用的是“
”而不是“space”
,这也会将字符串拆分为空格,而不是换行符。比如说跑步
set AppleScript's text item delimiters to "space"
return text items of "THISspaceISspaceAspaceSTRING"
set AppleScript's text item delimiters to " "
return text items of "This is a string
which is on two lines."
return paragraphs of "This is a string
which is on two lines."
返回
{"THIS", "IS", "A", "STRING"}
{"This", "is", "a", "string
which", "is", "on", "two", "lines."}
如您所见,“string\n其中”
是单个列表项
要想做你想做的事,你可以只使用字符串的段落
;比如说跑步
set AppleScript's text item delimiters to "space"
return text items of "THISspaceISspaceAspaceSTRING"
set AppleScript's text item delimiters to " "
return text items of "This is a string
which is on two lines."
return paragraphs of "This is a string
which is on two lines."
返回所需的值
{"This is a string", "which is on two lines."}
现在,我不完全清楚你到底想做什么。如果你想为一个特定的人得到这个,你可以写
tell application "Address Book"
set n to the note of the first person whose name is "Antal S-Z"
return paragraphs of n
end tell
您必须将其拆分为两个语句,因为我认为,的段落是一个命令,而第一行上的所有内容都是一个属性访问。(老实说,我通常通过反复试验发现这些东西。)
另一方面,如果你想为一组中的每个人都得到这个列表,那就稍微难一点。一个大问题是,没有便笺的人会为他们的便笺获得缺失值
,这不是字符串。如果您想忽略这些人,那么下面的循环将起作用
tell application "Address Book"
set ns to {}
repeat with p in ¬
(every person in group "Test Group" whose note is not missing value)
set ns to ns & {paragraphs of (note of p as string)}
end repeat
return ns
end tell
每个人…
位都会按照它所说的做,找到相关的人;然后我们提取他们笔记的段落(在提醒AppleScript p的笔记实际上是一个字符串之后)。在这之后,ns
将包含类似于{{“测试1”、“测试2”}、{“测试3”、“测试4”}
的内容,这非常好。我尝试了一些段落,但在阅读了你的语法之后,我明白了该怎么做