获取项目信息时出现问题(applescript)
我是一个非常好的苹果脚本编写者,并且需要一些帮助。我正在制作一个回收站应用程序,类似于 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
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
该错误是由表达式
info for item i ofrasht
引起的。子表达式item i oftrash
返回一个 (Finder) 项目对象。但是,info for
命令需要文件的别名或文件引用(请参阅AppleScript 语言指南)。有两种方法可以修复表达式。显式地将项目转换为别名,即:
或者不使用
info for
命令,只需使用 Finder 项目的size
属性:确保同时具有
RBPFMS
和free_space
在check
函数中声明为全局变量:另一个错误:在
中将括号作为字符串
放在RBPFMS 周围显示警报
语句:The error is caused by the expression
info for item i of trash
. The subexpressionitem i of trash
returns a (Finder) item object. Theinfo 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.:
Or instead of using the
info for
command, simply use the Finder item'ssize
property:Be sure to have both
RBPFMS
andfree_space
declared as global variables in thecheck
function:Another bug: put parentheses around
RBPFMS as string
in thedisplay alert
statement:该调用需要在“check()”前面加上“my”。
告诉 Finder 调用它的“检查”子例程是行不通的。 Finder 会告诉您它不知道如何“检查”。它将使用的词语是“Finder 无法继续检查”。但您可以告诉 Finder 调用您本地定义的“检查”子例程。当您调用子例程时,您只需在“check”前添加 my 前缀即可。每次从tell 块内部调用自己的子例程时都需要执行此操作。
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.