我是一个非常好的boyscripter,并希望得到一些帮助。我正在制作一个类似于Windows XP回收站的回收站应用程序。它当然是一滴水。当我将项目拖放到应用程序时,应用程序启动一个子程序,用于检查是否超出了回收站(废纸篓)的大小限制。但是,当我尝试获取垃圾箱中的项目信息时,出现的错误消息是:“Finder收到错误。找不到文件项目1。”我真的需要帮助:( 子程序如下:
on check()
tell application "Finder"
set the total_size to 0
set the trash_items to get every item in trash
if the trash_items is not {} then
repeat with i from 1 to the count of items in trash
set this_info to get info for item i of trash --ERROR ON THIS LINE
set the total_size to the total_size + (size of this_info)
end repeat
try
set the second_value to the free_space / (RBPFMS / 100)
if the total_size is greater than the second_value then
display alert "Size Limit Exceeded" message "The Recycle Bin cannot receive any more items because it can only use " & RBPFMS as string & " of your hard drive." buttons {"OK"} default button 1
return false
else
return true
end if
on error
set RBP to ((path to startup disk) as string) & "Recycle Bin Properties"
display dialog "Error: You have modified the properties file for the Recycle Bin. Do not modify the properties file. It is there to store information that is used to determine the properties for the Recycle Bin." with title "Property File Modified" with icon 0 buttons {"OK"} default button 1
set the name of RBP to "DELETE ME"
error number -128
end try
end if
end tell
end check
答案 0 :(得分:2)
错误是由表达式info for item i of trash
引起的。子表达式item i of trash
返回一个(Finder)项目对象。但是info for
命令需要对文件的别名或文件引用(请参阅AppleScript language guide)。
有两种方法可以修复表达式。明确地将项目转换为别名,即:
repeat with i from 1 to the (count of items) in trash
set this_info to get info for (item i of trash as alias)
set the total_size to the total_size + (size of this_info)
end repeat
或者不使用info for
命令,只需使用Finder项的size
属性:
repeat with i from 1 to the (count of items) in trash
set the total_size to the total_size + (size of item i)
end repeat
请务必在RBPFMS
函数中将free_space
和check
声明为全局变量:
on check()
global RBPFMS
global free_space
...
end
另一个错误:在RBPFMS as string
语句中将括号括在display alert
附近:
display alert "Size Limit Exceeded" message "The Recycle Bin cannot receive any more items because it can only use " & (RBPFMS as string) & " of your hard drive." buttons {"OK"} default button 1
答案 1 :(得分:1)
当我尝试调用子程序时,它出错“无法继续检查。”
电话需要在“check()”前面加上“my”。
告诉Finder调用其“check”子程序将不起作用。 Finder会告诉你它不知道如何“检查”。它将使用的词语是“Finder无法继续检查”。但是你可以告诉Finder调用你本地定义的“check”子程序。在调用子例程时,只需将 my 前缀为“check”。每次从tell块中调用自己的子程序时,都需要这样做。