2011-01-23 15 views
6

Tôi là một người viết bài khá đặc biệt và đã viết kịch bản trong một thời gian dài. Ứng dụng tôi hiện đang tạo liên quan đến việc sử dụng ứng dụng "Sự kiện cơ sở dữ liệu". Tôi đang cố gắng đặt giá trị của một trường bằng cách sử dụng chương trình con. Rõ ràng, tôi "không thể tiếp tục set_duration" và tôi không có ý tưởng gì có thể sai. Mã nguồn hiện tại là dưới đây.Vấn đề với chương trình con Applescript

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 

Trả lời

10

Vấn đề là AppleScript đang xử lý set_duration làm thuật ngữ từ database "Folder Cleanup Wizard" hoặc từ application "Database Events", nhờ vào số tell b khóa. (Bên ngoài một khối tell, chỉ cần đồng bằng set_duration() sẽ hoạt động.) Để thực hiện việc này, bạn cần sử dụng my set_duration(), thông báo cho AppleScript xem trong tập lệnh hiện tại của hàm. Vì vậy, trong trường hợp này, bạn sẽ có

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

Tôi nghĩ rằng điều này là do AppleScript là nhận được bối rối nơi set_duration sống

Do something như thế này

tell me to set value_to_set to set_duration() 
tell record "Duration" to make new field with properties {name:"Days", value:value_to_set} 

Tôi nghĩ rằng sẽ làm việc cho bạn