什么是Applescript错误;(*无法将“地址、姓名、计数器”的结尾设置为“f”。l@place.vic.gov.au&"(")";告诉我?

什么是Applescript错误;(*无法将“地址、姓名、计数器”的结尾设置为“f”。l@place.vic.gov.au&"(")";告诉我?,applescript,scope,apple-mail,Applescript,Scope,Apple Mail,这是我的脚本,基于一个选项: 在运行时,我遇到以下错误: 当我创建了一个范围证明脚本,以表明告诉应用程序“邮件”块范围不是问题时,它可以工作: 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

这是我的脚本,基于一个选项:

在运行时,我遇到以下错误:

当我创建了一个范围证明脚本,以表明告诉应用程序“邮件”块范围不是问题时,它可以工作:

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
从范围(问题先前迭代的剩余部分)来看:

将x设置为3

如果没有全局变量声明,则 使用copy或set命令声明的变量通常受到限制 到脚本的运行处理程序,使其隐式地位于该脚本的本地 运行处理程序。但是,处理程序或嵌套脚本对象可以声明 使用全局声明访问同一变量


我做了一些假设:

set theFile to POSIX path of ((path to desktop folder as text) & "unsubscribe.csv")
set counter to 0
set theAddrresses to {"Address, Name, Counter" & return}
set uniqueAddresses to {}

tell application "Mail"
    set emailSelection to (get 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 uniqueAddresses contains theSender then
            log "***     Double:    " & theSender & "    ***"
            theSender & "***********" & return
        else
            -- I think you want to increment your counter ?
            set counter to counter + 1

            copy theSender to the end of uniqueAddresses
            set theAddrresses to theAddrresses & theSender & "," & theName & "," & counter & "," & return
            log theAddrresses
        end if
    end repeat
end tell

do shell script "echo " & quoted form of (theAddrresses as text) & " > " & quoted form of theFile
delay 1
do shell script "open " & quoted form of theFile

看起来您留下了一些测试代码,或者没有正确编辑复制的行之一。问题在于:

copy theSender to the end of theAddresses
set theAddresses to theAddresses & theSender & "," & theName & "," & counter & "," & return
log theAddresses
在第一行中,您使用语法将发送者添加到列表(
end of
)。由于地址是一个字符串,而不是一个列表,因此出现了一个错误

在第二个版本中不会出现该错误,因为您使用了正确的语法来追加字符串:

set theAddresses to theAddresses & theSender & return

是打字错误吗<编码>设置地址而不是
设置地址
?是的,你说得对,有个打字错误。已修复,但现在出现另一个错误:(无法将“Address,Name,Counter”的结尾设置为“first”。last@localcouncil.vic.gov.au“)@tptcat:我建议编辑问题标题和代码,以反映您对原始问题的解决方案,bc我认为由此产生的问题对未来的读者更有利。这是一个很好的协议吗?啊,感谢两个变量,地址和唯一地址。我昨天成功地编写了这个脚本(由于AS崩溃而忘记保存和丢失),并使用了这两个脚本,但在重写时忘记了区分。我想这就解释了错误的本质。为什么选择shell脚本?(我对shell/bash了解不多)在写入文本文件时,使用shell脚本比打开和关闭access更容易。这给了我一个权限错误。解决这个问题的最好办法是什么?在脚本中,或者我可以设置文件夹权限以允许作为编辑器(或者是shell?)执行操作吗?需要将文件路径的“POSIX路径文件”转换为shell语法。是的,谢谢。你是对的。我正在重写前一天从内存中编写的脚本,但忘记了我需要两个列表,一个字符串用于搜索以前的点击内容,另一个对象列表包含3个数据项。最后,我用一张单子分别做了一点。我想我可以在一个集合中搜索以前的点击,但更简单的方法是说“如果发件人包含在地址中,那么…”并将3个数据项存储在单独的对象列表中。
copy theSender to the end of theAddresses
set theAddresses to theAddresses & theSender & "," & theName & "," & counter & "," & return
log theAddresses
set theAddresses to theAddresses & theSender & return