添加文本路径
Add path to text
我有一个重复
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
简而言之,您在脚本开始时打开 write-out 文件,在重复循环内按顺序写入数据,然后在结束时关闭文件。
开头的 try
块处理一个常见问题:如果您的脚本在 close
语句之前出错,文件句柄保持打开状态,如果您尝试打开它可能会出错 再次;此 try
块检测到错误,并尝试关闭并重新打开文件句柄。
如果相关应用定义了自己的 write
命令,您可能需要在 write
语句之前放置关键字 my
。
我有一个重复
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
简而言之,您在脚本开始时打开 write-out 文件,在重复循环内按顺序写入数据,然后在结束时关闭文件。
开头的 try
块处理一个常见问题:如果您的脚本在 close
语句之前出错,文件句柄保持打开状态,如果您尝试打开它可能会出错 再次;此 try
块检测到错误,并尝试关闭并重新打开文件句柄。
如果相关应用定义了自己的 write
命令,您可能需要在 write
语句之前放置关键字 my
。