我是AppleScript核心部分,我很快就會從購買打字機和搬進山區。AppleScript:試圖在提供POSIX路徑時寫入文件
任何人都可以,請給我解釋一下爲什麼這個失敗:
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
和
set mah_file to POSIX file "/Users/me/folder/fileinfo.txt" as alias
和
set mah_file to POSIX file "/Users/me/folder/fileinfo.txt" as text
而且,由於AppleScript的乾脆就不告訴我爲什麼這是行不通的,我很好,真正失去了我的腦海裏。
哦,上帝是這個捂臉時刻。謝謝,不過。 – Jonline