gpt4 book ai didi

applescript - Applescript子例程出现问题

转载 作者:行者123 更新时间:2023-12-04 03:02:53 25 4
gpt4 key购买 nike

我是一位非常出色的applescripter,并且已经编写脚本很长时间了。我当前正在创建的应用程序涉及“数据库事件”应用程序的使用。我试图通过使用子例程来设置字段的值。显然,我“无法继续set_duration”,而且我不知道可能出什么问题。当前的源代码如下。

property first_run : true
on run
if first_run then
display dialog "THIS APPLICATION IS DESIGNED TO CLEAN UP THE FOLDER CONTAINING IT." & return & return & "After a certain number of days that you set, every item in that folder that has not been used for that duration will automatically be moved to a folder named \"Unused Items\"." with icon 1 buttons {"Cancel", "OK"} default button 2
set first_run to false
end if
tell application "Database Events"
set quit delay to 0
try
get database "Folder Cleanup Wizard"
on error
make new database with properties {name:"Folder Cleanup Wizard"}
tell database "Folder Cleanup Wizard"
make new record with properties {name:"Duration"}
tell record "Duration" to make new field with properties {name:"Days", value:set_duration()} --> UNKNOWN ERROR
end tell
end try
end tell
end run

on set_duration()
try
set duration to the text returned of (display dialog "Enter the minimum duration period (in days) that files and folders can remain inactive before they are moved to the \"Unused Items\" folder." default answer "" with title "Set Duration") as integer
if the duration is less than 0 then
display alert "Invalid Duration" message "Error: The duration cannot be a negative number." buttons {"OK"} default button 1
set_duration()
end if
on error
display alert "Invalid Duration" message "Error: \"" & (duration as string) & "\" is not a valid duration time." buttons {"OK"} default button 1
set_duration()
end try
end set_duration

最佳答案

问题在于,由于set_duration块,AppleScript正在将database "Folder Cleanup Wizard"作为application "Database Events"tell的术语。 (在tell块之外,仅普通的set_duration()就可以使用。)为了解决这个问题,您需要使用my set_duration(),它告诉AppleScript在当前脚本中查找该功能。因此,在这种情况下,

...
tell record "Duration" to ¬
make new field with properties {name:"Days", value:my set_duration()}
...

关于applescript - Applescript子例程出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4777327/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com