I am a fairly exceptional applescripter, and have been writing scripts for a long time. The application I am currently creating involves the use of the "Database Events" application. I am trying to set the value of a field by using a subroutine. Apparently, I "can't continue set_duration" and I have no idea what could be wrong. The current source code is below.
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
The problem is that AppleScript is treating set_duration
as a term from database "Folder Cleanup Wizard"
or from application "Database Events"
, thanks to the tell
blocks. (Outside a tell
block, just plain set_duration()
will work.) In order to get around this, you need to use my set_duration()
, which tells AppleScript to look in the current script for the function. So, in this case, you'd have
...
tell record "Duration" to ¬
make new field with properties {name:"Days", value:my set_duration()}
...
I think this is because Applescript is getting confused where set_duration lives
Do something like this
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}
I think that will work for you
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With