Applescript适用于脚本编辑器,但不适用于Xcode 5

时间:2014-09-22 00:22:48

标签: xcode xcode5 applescript applescript-objc

晚上好, 我试图理解为什么我可以在Applescript编辑器中运行以下脚本但是无法在Xcode Cocoa-Applescript应用程序中成功运行它。

有人可以解释一下为什么这个函数不能在Xcode中运行以及我需要做些什么来让它正常运行?

set this_data to ((current date) as string) & space & "WHY DOESN'T THIS LOG!!!!" & return
set this_file to (((path to desktop folder) as string) & "MY LOG FILE")
my write_to_file(this_data, this_file, true)


on write_to_file(this_data, target_file, append_data)
 try
    set the target_file to the target_file as string
    set the open_target_file to open for access file 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

1 个答案:

答案 0 :(得分:1)

这是我无法解释的Xcode行为之一,但是如果您像这样添加tell current application它会起作用:

tell current application to set the open_target_file to open for access file target_file with write permission

将整个函数放在tell current application块中可能会更好。