Axw*_*ack 2 applescript automator
我的地址簿注释字段中有两行
Test 1
Test 2
Run Code Online (Sandbox Code Playgroud)
我想将每一行作为单独的值或从notes字段中获取最后一行.
我试过这样做:
tell application "Address Book"
set AppleScript's text item delimiters to "space"
get the note of person in group "Test Group"
end tell
Run Code Online (Sandbox Code Playgroud)
但结果是
{"Test 1
Test 2"}
Run Code Online (Sandbox Code Playgroud)
我在找 :
{"Test1","Test2"}
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
您的代码存在一些问题.首先,你从来没有真正要求注释的文本项目:-)你只需要获取原始字符串.第二个是set AppleScript's text item delimiters to "space"将文本项分隔符设置为文字字符串space.因此,例如,跑步
set AppleScript's text item delimiters to "space"
return text items of "THISspaceISspaceAspaceSTRING"
Run Code Online (Sandbox Code Playgroud)
回报
{"THIS", "IS", "A", "STRING"}
Run Code Online (Sandbox Code Playgroud)
其次,即使你有" "而不是"space",这会在空格上分割你的字符串,而不是新行.例如,跑步
set AppleScript's text item delimiters to " "
return text items of "This is a string
which is on two lines."
Run Code Online (Sandbox Code Playgroud)
回报
{"This", "is", "a", "string
which", "is", "on", "two", "lines."}
Run Code Online (Sandbox Code Playgroud)
如您所见,"string\nwhich"是一个列表项.
要做你想做的事,你可以使用paragraphs of STRING; 例如,跑步
return paragraphs of "This is a string
which is on two lines."
Run Code Online (Sandbox Code Playgroud)
返回所需的
{"This is a string", "which is on two lines."}
Run Code Online (Sandbox Code Playgroud)
现在,我不是完全清楚究竟要做些什么.如果你想为特定的人获得这个,你可以写
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
Run Code Online (Sandbox Code Playgroud)
你必须将它分成两个语句,因为我认为paragraphs of ...是一个命令,而第一行的所有内容都是属性访问.(老实说,我经常通过反复试验发现这些事情.)
另一方面,如果你想为一个小组中的每个人获得这个列表,那就稍微困难了.一个大问题是没有笔记的人会得到missing value他们的笔记,这不是一个字符串.如果你想忽略这些人,那么以下循环将起作用
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
Run Code Online (Sandbox Code Playgroud)
这every person ...一点完全符合它的说法,得到相关人员; 然后我们提取他们的音符段落(在提醒AppleScript之后,note of p确实是一个字符串).在此之后,ns将包含类似的东西{{"Test 1", "Test 2"}, {"Test 3", "Test 4"}}.
| 归档时间: |
|
| 查看次数: |
4129 次 |
| 最近记录: |