这是我的脚本,基于在 SO上挑选的一个:
set theFile to (path to desktop folder as text) & "unsubscribe.csv"
set theRecord to ""
set counter to 1
set theAddresses to "Address, Name, Counter" & return
try
set theFileID to open for access file theFile with write permission
tell application "Mail"
set emailSelection to selection
repeat with eachMessage in emailSelection
-- log sender of the_message
set theSender to extract address from sender of eachMessage
set theName to extract name from sender of eachMessage
if theAddresses contains theSender then
log "*** Double: " & theSender & " ***"
theSender & "***********" & return
else
copy theSender to the end of theAddresses
set theAddresses to theAddresses & theSender & "," & theName & "," & counter & "," & return
log theAddresses
end if
end repeat
end tell
try
write theAddresses to theFileID as «class utf8»
on error theError
log theError
end try
on error theError
log theError
try
close access file theFile
end try
end try
运行时出现此错误:
"(*Can’t set end of "Address, Name, Counter " to "f.l@place.vic.gov.au".*)"
当我创建范围证明脚本时,向自己展示告诉应用程序“邮件”块范围不是问题,它可以工作:
try
set theFile to (path to desktop folder as text) & "test3.csv"
set theFileID to open for access file theFile with write permission
set theAddresses to "Address, Name, Counter" & return
tell application "Mail"
set emailSelection to selection
set theMsg to the first item in emailSelection
set theSender to extract address from sender of theMsg
end tell
set theAddresses to theAddresses & theSender & return
try
write theAddresses to theFileID as «class utf8»
on error theError
log theError
end try
close access file theFile
on error theError
close access file theFile
end try
来自 Scope 上的Applescript 文档(问题的先前迭代的残余):
将 x 设置为 3
在没有全局变量声明的情况下,使用 copy 或 set 命令声明的变量的范围通常仅限于脚本的运行处理程序,使其隐式地位于该运行处理程序的本地。但是,处理程序或嵌套脚本对象可以使用全局声明来声明相同的变量以访问它。