Problema al obtener información para el artículo (applecript)

I am a pretty good applescripter, and would like some help with this. I am making a recycle bin application, similar to that of the Windows XP Recycle Bin. It is of course a droplet. When I drop items onto the application, the application starts a subroutine designed to check whether the size limit of the Recycle Bin (Trash) was exceeded. However, when I try to get the info for the items in the Trash, the error message that comes up is: "Finder got an error. File item 1 wasn't found." I really need help :( The subroutine is below:

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

preguntado el 08 de enero de 11 a las 17:01

2 Respuestas

The error is caused by the expression info for item i of trash. The subexpression item i of trash returns a (Finder) item object. The info for command however requires an alias or file reference to the file (see AppleScript language guide).

There are two ways to fix the expression. Explicitly cast the item to an alias, i.e.:

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

Or instead of using the info for command, simply use the Finder item's size propiedad:

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

Be sure to have both RBPFMS y free_space declared as global variables in the check función:

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

Another bug: put parentheses around RBPFMS as string en el objeto display alert declaración:

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

Respondido el 10 de enero de 11 a las 21:01

Thank you so much! That problem is now resovled. However, when I try to call the subroutine, it errors "Can't continue check." Could you please check all of the statements inside the subroutine? That would be great. :) - sombra de fuego52

The variables free_space and RBPFMS aren't defined in the check function. - Sakra

I know. I made them global varibles so they can be used anywhere. - sombra de fuego52

...on second thought, I might not have. I will check. - sombra de fuego52

I checked to make sure that they were global, and they were. I don't know what could be causing the error. :( - sombra de fuego52

when I try to call the subroutine, it errors "Can't continue check."

The call needs a "my" in front of "check()".

Telling the Finder to call its "check" subroutine won't work. The Finder will tell you that it doesn't know how to "check". The words it will use are "Finder can't continue check." But you can tell the Finder to call your locally-defined "check" subroutine. You simply prefix my to "check" when you call the subroutine. You need to do this every time you call your own subroutine from inside a tell block.

Respondido el 01 de enero de 14 a las 05:01

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.