AppleScript:在提供POSIX路径时尝试写入文件
我是AppleScript nub,离买打字机和搬进山里还有很长的路要走 请任何人向我解释一下为什么失败:AppleScript:在提供POSIX路径时尝试写入文件,applescript,Applescript,我是AppleScript nub,离买打字机和搬进山里还有很长的路要走 请任何人向我解释一下为什么失败: set mah_file to POSIX file "/Users/me/folder/fileinfo.txt" set mah_data to "some text!!!!!!" on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean) tr
set mah_file to POSIX file "/Users/me/folder/fileinfo.txt"
set mah_data to "some text!!!!!!"
on write_to_file(this_data, target_file, append_data) -- (string, file path as string, boolean)
try
set the target_file to the target_file as text
set the open_target_file to ¬
open for access file of target_file with write permission
if append_data is false then ¬
set eof of the open_target_file to 0
write this_data to the open_target_file starting at eof
close access the open_target_file
return true
on error
try
close access file target_file
end try
return false
end try
end write_to_file
write_to_file(mah_data, mah_file, true)
尽管成功了:
set mah_file to choose file
set mah_data to "some text!!!"
-- the rest is identical
我试过:
set mah_file to POSIX file "/Users/me/folder/fileinfo.txt" as file
及
及
既然AppleScript不厌其烦地告诉我为什么它不起作用,我真的是疯了 省略
文件
和POSIX文件
关键字:
set mah_file to "/Users/me/folder/fileinfo.txt"
...
set the open_target_file to open for access mah_file with write permission
省略
文件
和POSIX文件
关键字:
set mah_file to "/Users/me/folder/fileinfo.txt"
...
set the open_target_file to open for access mah_file with write permission
read
和write
默认情况下也使用主编码(如MacRoman或MacJapanese)。将添加为«类utf8»
以在UTF-8文件中保留非ASCII字符
写作:
set b to open for access "/tmp/1" with write permission
set eof b to 0
write "α" to b as «class utf8»
close access b
附加:
set b to open for access "/tmp/1" with write permission
write "ア" to b as «class utf8» starting at eof
close access b
阅读:
read "/usr/share/dict/connectives" as «class utf8»
read
和write
默认情况下也使用主编码(如MacRoman或MacJapanese)。将添加为«类utf8»
以在UTF-8文件中保留非ASCII字符
写作:
set b to open for access "/tmp/1" with write permission
set eof b to 0
write "α" to b as «class utf8»
close access b
附加:
set b to open for access "/tmp/1" with write permission
write "ア" to b as «class utf8» starting at eof
close access b
阅读:
read "/usr/share/dict/connectives" as «class utf8»
您可以结合使用echo命令和>>将文本写入文件 如果纺织品不存在,将创建一个新的纺织品 如果文本文件已经存在并且 使用>可以覆盖具有相同名称的现有纺织品 使用>>时,文本将添加到现有文件中
set mypath to "/Users/" & (short user name of (system info)) & "/Desktop/file.txt" as string
set myText to "text to write in the text file" as string
do shell script "echo " & "\"" & myText & "\"" & ">>" & mypath
mypath是和POSIX path
希望这就是您正在搜索的内容您可以结合使用echo命令和>>将文本写入文件 如果纺织品不存在,将创建一个新的纺织品 如果文本文件已经存在并且 使用>可以覆盖具有相同名称的现有纺织品 使用>>时,文本将添加到现有文件中
set mypath to "/Users/" & (short user name of (system info)) & "/Desktop/file.txt" as string
set myText to "text to write in the text file" as string
do shell script "echo " & "\"" & myText & "\"" & ">>" & mypath
mypath是和POSIX path
希望这就是你一直在寻找的哦,上帝,这是一个面对面的时刻。不过,谢谢。哦,天哪,这是一个面对面的时刻。不过谢谢你。