Applescript在脚本编辑器中工作,但不在Xcode 5中
问题描述:
晚上好, 我想了解为什么我可以在Applescript Editor中运行下面的脚本,但无法在Xcode Cocoa-Applescript应用程序中成功运行它。Applescript在脚本编辑器中工作,但不在Xcode 5中
有人可以解释为什么这个函数不能在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
答
这是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
块。