2011-01-23 16 views
6

Soy un manzanacripter bastante excepcional y he estado escribiendo guiones durante mucho tiempo. La aplicación que estoy creando actualmente implica el uso de la aplicación "Eventos de base de datos". Estoy tratando de establecer el valor de un campo usando una subrutina. Aparentemente, "no puedo continuar set_duration" y no tengo idea de qué podría estar mal. El código fuente actual está abajo.Problema con la subrutina de 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 

Respuesta

10

El problema es que AppleScript está tratando set_duration como un término de database "Folder Cleanup Wizard" o de application "Database Events", gracias a tell b cabellos. (Fuera de un bloque tell, simplemente funcionará set_duration()). Para evitar esto, necesita usar my set_duration(), que le dice a AppleScript que busque en el script actual para la función. Entonces, en este caso, tendrías

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

Creo que esto se debe a que Applescript se está confusa, donde set_duration vive

hacer algo como esto

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} 

Creo que va a trabajar para usted

Cuestiones relacionadas