Applescript 将路径添加到文本

Applescript 将路径添加到文本,applescript,Applescript,我重复了一次,这已经发生了 repeat with myrecordID in rtetr set refpdf to field "File Attachments" of record myrecordID if refpdf is "" then set noref to noref + 1 else set

我重复了一次,这已经发生了

   repeat with myrecordID in rtetr
            set refpdf to field "File Attachments" of record myrecordID
            if refpdf is "" then
                set noref to noref + 1
            else
                set refpdf2 to POSIX path of (docs & "/PDF" & refpdf1)
                set thePath to refpdf2
                set thePath1 to my convertPathToAlias(thePath)
                set thePath1 to thePath1 as text
            end if
            
        end repeat
变量是某些文件的路径 我想将这个变量写入一个文本文件,并将每个路径添加到一行。 但是当我尝试的时候

set myFile to open for access addtemp with write permission
        write namesText to myFile
        close access myFile
它只写最后一个变量,而不是所有的变量

我也试过这个

try
        set fileDescriptor to open for access addtemp with write permission
        write thePath1 & return to fileDescriptor
        close access fileDescriptor
    on error e number n
        try
            close access file addtemp
        end try
        display dialog "Error: " & e & " - number: " & n buttons {"Cancel"} default button "Cancel"
    end try

但是没有机会

好的,似乎您正在为一些您没有提到的应用程序使用
告诉
块-
将refpdf设置为记录myrecordID的字段“文件附件”
不是标准的AppleScript,不会自行编译-但是使用通用的应用程序名称,我想你想要的是这样的东西(请记住用相关应用程序的名称替换“通用名称”):

简言之,您可以在脚本开始时打开写出文件,在重复循环中按顺序写入数据,然后在结束时关闭文件

开头的
try
块处理一个常见问题:如果脚本在
close
语句之前出错,则文件句柄保持打开状态,如果再次尝试打开,则可能出错;此
try
块检测到错误,并尝试关闭和重新打开文件句柄


如果有问题的应用程序定义了自己的
write
命令,您可能需要将关键字
my
放在
write
语句之前。

A
set
命令覆盖以前的值。如果你想附加一些东西,你需要一个集合类型或者连接这些值。你能显示更多的代码吗。我们需要了解您是如何构建重复循环的。谢谢,添加了更多详细信息@TedWrigleThanks以获得完整答案,很抱歉,我不知道我应该输入进程名称,但脚本现在工作正常。请注意,我不知道为什么,使用此脚本创建的文件,我的下一个项目是一个重复循环,以获得我们在这里创建的文件的所有段落,它给了我错误。我不知道我应该如何区分不同,我在测试文件中写入一些文件的路径并运行我的脚本,它可以正常工作,但当我给出使用上面脚本中的文本文件创建的脚本文件时,它给了我错误“保存更改的属性时出错,文件路径用于mail app读取文件地址并添加到新邮件中。要明确,我手动创建的文件和脚本中的文件看起来相同,但不知道为什么会发生此问题您要写入的路径是什么?”?
try
    set myFile to open for access addtemp with write permission
on error
    close access addtemp
    set myFile to open for access addtemp with write permission
end try

tell application "Generic Name"
    repeat with myrecordID in rtetr
        set refpdf to field "File Attachments" of record myrecordID
        if refpdf is "" then
            set noref to noref + 1
            -- write out a notice that there was no data, with a line break after
            write "No Reference" & return to myFile
        else
            set refpdf2 to POSIX path of (docs & "/PDF" & refpdf1)
            set thePath to refpdf2
            set thePath1 to my convertPathToAlias(thePath)
            set thePath1 to thePath1 as text
            -- write out the data, with a line break after
            write thePath1 & return to myFile
        end if
    end repeat
end tell
close access myFile