Проблема с получением информации для элемента (applecript) - PullRequest
0 голосов
/ 08 января 2011

Я довольно хороший криптограф, и хотел бы помочь с этим. Я делаю приложение для корзины, похожее на 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

Ответы [ 2 ]

2 голосов
/ 08 января 2011

Ошибка вызвана выражением 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 просто используйте свойство size элемента Finder:

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 голос
/ 01 января 2014

при попытке вызвать подпрограмму выдает ошибку «Не удается продолжить проверку».

Для вызова требуется «my» перед «check ()».

Указание Finder вызвать его подпрограмму «check» не будет работать.Искатель скажет вам, что он не знает, как «проверить».Он будет использовать следующие слова: «Finder не может продолжить проверку».Но вы можете сказать Finder вызвать вашу локальную подпрограмму «check».Вы просто добавляете префикс my к «чеку» при вызове подпрограммы.Это необходимо делать каждый раз, когда вы вызываете свою собственную подпрограмму из блока Tell.

...