如何解决为文本添加路径
我重复了一次
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
但没有机会
解决方法
好吧,似乎您正在使用tell
块处理尚未提及的某些应用程序-set refpdf to field "File Attachments" of record myrecordID
不是标准的AppleScript,不会自行编译-而是使用通用的应用程序名称,我想您需要这样的内容(请记住,将“通用名称”替换为相关应用程序的名称):
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
简而言之,您可以在脚本的开头打开写出的文件,在重复循环内依次写入数据,然后在结尾处关闭文件。
开头的try
块处理一个常见的问题:如果您的脚本在close
语句之前出错,则文件句柄保持打开状态,如果尝试打开它,则可能出错。再次; try
块检测到错误,然后尝试关闭并重新打开文件句柄。
如果相关应用定义了自己的my
命令,则可能需要在write
语句前放置关键字write
。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。