0

我是一个非常好的applescripter,并希望得到一些帮助。我正在制作一个类似于 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
4

2 回答 2

2

错误是由表达式引起的info for item i of trash。子表达式item i of trash返回一个 (Finder) 项目对象。然而,该info for命令需要对该文件的别名或文件引用(请参阅AppleScript 语言指南)。

有两种方法可以修复表达式。将项目显式转换为别名,即:

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

确保在函数中同时具有RBPFMSfree_space声明为全局变量check

on check()
    global RBPFMS
    global free_space
    ...
end

另一个错误:RBPFMS as stringdisplay 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
于 2011-01-08T18:12:05.070 回答
1

当我尝试调用子例程时,它会出错“无法继续检查”。

调用需要在“check()”前面加上“my”。

告诉 Finder 调用它的“检查”子程序是行不通的。Finder 会告诉您它不知道如何“检查”。它将使用的词是“Finder 无法继续检查”。但是您可以告诉 Finder 调用您本地定义的“检查”子例程。当您调用子例程时,您只需在my前面加上“check”即可。每次从 tell 块中调用自己的子例程时,都需要这样做。

于 2014-01-01T01:56:48.387 回答