2011-01-23 36 views
6

Oldukça sıradışı bir elyazısıyım ve uzun süre senaryo yazıyor. Şu anda oluşturmakta olduğunuz uygulama "Veritabanı Olayları" uygulamasının kullanımını içerir. Bir alanın değerini bir alt program kullanarak ayarlamaya çalışıyorum. Görünüşe göre, "set_duration'a devam edemiyorum" ve neyin yanlış olabileceğine dair hiçbir fikrim yok. Mevcut kaynak kodu aşağıdadır.Applescript alt yordamıyla ilgili sorun

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 

cevap

10

sorun olduğunu AppleScript olduğunu için o işe yarayacak bu

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} 

gibi şeyler yapın yaşadığı AppleScript karıştı çünkü bu olduğunu düşünüyorum set_duration'u database "Folder Cleanup Wizard" veya application "Database Events"'dan tell b'ye uygun bir şekilde işleme koymaktadır. kilitler. (tell bloğunun dışında, sadece set_duration() numaralı bloğun dışında çalışacaktır.) Bunun üstesinden gelmek için, AppleScript'in işlev için geçerli komut dosyasına bakmasını söyleyen my set_duration() kullanmanız gerekir. Yani, bu durumda,

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