我正在尝试运行一个AppleScript,以便通过gmail(web)查找特定发件人的新电子邮件->打开电子邮件->并在searchTerm定义的电子邮件中打开特定的超链接。
经过反复试验,我发现了一个AppleScript,它可以使用javascript来完成这项工作。来源:cubemg
脚本在跨度中的searchTerm定义的收件箱中查找发件人。然后,它会在电子邮件正文的标签中寻找searchTerm以获取超链接。
to clicktagName(thetagName, elementnum)
tell application "Safari"
do JavaScript "document.getElementsByTagName('" & thetagName & "')[" & elementnum & "].click();" in document 1
end tell
end clicktagName
to getInputBytagName(thetag, num)
tell application "Safari"
set input to do JavaScript "
document.getElementsByTagName('" & thetag & "')[" & num & "].innerHTML;" in document 1
end tell
return input
end getInputBytagName
to clicktag(tagName, num)
tell application "Safari"
set input to do JavaScript "
var tagName = '" & tagName & "';
var num = '" & num & "';
var x = document.getElementsByTagName(tagName)[num].click();" in document 1
end tell
end clicktag
set x to 0
set tagName to "span"
set searchTerm to "email@email.com"
set trialInnerHTML to getInputBytagName(tagName, x)
repeat until tagName = searchTerm
if trialInnerHTML = searchTerm then
clicktag(tagName, x)
exit repeat
end if
set x to x + 0
end repeat
delay 0
set x to 0
set tagName to "a"
set searchTerm to "Name of link"
repeat 500 times
set trialInnerHTML to getInputBytagName(tagName, x)
if trialInnerHTML = searchTerm then
clicktag(tagName, x)
exit repeat
end if
set x to x + 1
end repeat
这实际上已经在工作。但是,脚本无法在后台连续运行。它需要手动运行。一旦满足条件并找到电子邮件,脚本便会停止。
我正在尝试更改代码,以便重复该过程,直到收到与searchTerm相匹配的新电子邮件为止。
使用重复直到行:重复直到tagName = searchTerm
但是,与搜索词匹配的未读新电子邮件不会打开。仅当收件箱中已包含xx发件人的电子邮件时,该脚本才起作用。
任何线索都值得赞赏。
谢谢