使用AppleScriptObjC读取内容文件并向其写入新内容

时间:2013-05-07 05:08:00

标签: xcode applescript applescript-objc

我想编写一个读取文件的AppleScript代码,并在修改输入对话框

时写回

喜欢

set theFile to "/private/etc/hosts"
set theFileContent to read theFile

我使用Xcode 4.6创建了一个文本字段和2个按钮。我想使用上面的代码来读取hosts文件的内容并在文本字段中显示它,当我修改文本字段并单击“保存”按钮时,它应该使用管理员权限写回主机文件。我试过,但他们不为我工作,也许我不知道applescript和applescriptobjc之间的区别。

请帮助我。

提前致谢

1 个答案:

答案 0 :(得分:0)

试试这个:

set theFile to ("your/Path/...")
set theFileHandle to open for access theFile write permission true
write "someText" to theFileHandle
close access theFileHandle
相关问题