我想在applescript中制作一个小应用程序,轮询剪贴板的更改,并在检测到任何更改后,将剪贴板的内容转储到文本文件中。这是我想出的代码,它创建了文件,但没有写入任何内容。我究竟做错了什么?
property oldvalue : missing value
on idle
local newValue
set newValue to the clipboard
if oldvalue is not equal to newValue then
try
tell application "Finder"
try
set the_file to "/Users/xxx/Documents/dump2.txt" as POSIX file as alias
on error
set the_file to (make new document file at ("/Users/xxx/Documents/" as POSIX file as alias) with properties {name:"dump2", text:""})
end try
end tell
try
open for access the_file with write permission
write newValue to file the_file starting at eof
close access the_file
on error
try
close access the_file
end try
end try
end try
set oldvalue to newValue
end if
return 1
end idle