我使用此AppleScript获取所选电子邮件的内容:
using terms from application "Mail"
on run {input, parameters}
set mailContents to {}
repeat with aMessage in input
set end of mailContents to content of aMessage
end repeat
return mailContents
end run
end using terms from
结果如下:
{"

Here's some text followed by a longer URL, which is cut by a line break!
http://www.XYZ.net/diario/actualidad/economia/20140714/-ciudad-bar
ata-para-el-turismo_353_34541.html
"}
我想使用这些特定邮件中的所有链接来处理,但是不可能使用之前的示例中显示的划分的URL。 那么如何告诉AppleScript将URL保持在一起呢?
答案 0 :(得分:1)
试试这个。我从你的mailContents示例开始。您最终得到了httpLinks变量中的链接列表。这假设每个链接以“http”开头并以“html”结尾。祝你好运。
set mailContents to {"

Here's some text followed by a longer URL, which is cut by a line break!
http://www.XYZ.net/diario/actualidad/economia/20140714/-ciudad-bar
ata-para-el-turismo_353_34541.html
"}
set httpLinks to {}
repeat with i from 1 to count of mailContents
set thisContent to item i of mailContents
-- remove all return characters (mac, unix, and windows characters)
set AppleScript's text item delimiters to {character id 10, character id 13, character id 13 & character id 10}
set textItems to text items of thisContent
set AppleScript's text item delimiters to ""
set newText to textItems as text
-- find links
set AppleScript's text item delimiters to "http"
set textItems to text items of newText
if (count of textItems) is greater than 1 then
set AppleScript's text item delimiters to "html"
repeat with j from 2 to count of textItems
set linkItems to text items of (item j of textItems)
set thisLink to "http" & item 1 of linkItems & "html"
set end of httpLinks to thisLink
end repeat
end if
set AppleScript's text item delimiters to ""
end repeat
return httpLinks
答案 1 :(得分:0)
这不会破坏线条,希望你能以某种方式使用它:
tell application "Mail"
set mailSelection to selection
set mailContents to {}
repeat with mail in mailSelection
set end of mailContents to content of mail
end repeat
get mailContents
end tell
答案 2 :(得分:0)
非常感谢!我必须稍微自定义您的脚本,因为并非每个URL都以html
结尾。此外,我使用了source
消息而不是content
,因为删除的换行符产生了结果,将URL与其他文本分开非常困难。他们之间没有空间。这是我的实际代码:
`使用应用程序中的术语" Mail"
在运行{输入,参数}
将mailContents设置为{}
在输入中重复使用aMessage
将mailContents的结尾设置为aMessage的源
结束重复
set httpLinks to {}
repeat with i from 1 to count of mailContents
set thisContent to item i of mailContents
-- remove all return characters (mac, unix, and windows characters)
set AppleScript's text item delimiters to {"=09", "=" & character id 10, "=" & character id 13, "3D", character id 92}
set textItems to text items of thisContent
set AppleScript's text item delimiters to ""
set newText to textItems as rich text
-- find links
set AppleScript's text item delimiters to "http"
set textItems to text items of newText
if (count of textItems) is greater than 1 then
set AppleScript's text item delimiters to "target"
repeat with j from 2 to count of textItems
set linkItems to text items of (item j of textItems)
set thisLink to "http" & item 1 of linkItems & "target"
set end of httpLinks to thisLink
end repeat
end if
set AppleScript's text item delimiters to ""
end repeat
set list1 to httpLinks
set list2 to {}
repeat with x from 1 to count of items of list1
set n to item x of list1
if n is not in list2 then set end of list2 to n
end repeat
return list2
end run
结束使用来自`
的条款