我是 AppleScript 小伙子,离购买打字机和搬进山里只有片刻路程。
请任何人向我解释为什么会失败:
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 懒得告诉我为什么这不起作用,我很好,真的疯了。