2011-01-23 14 views
6

के साथ समस्या मैं काफी असाधारण सेबस्क्रिप्टर हूं, और लंबे समय तक स्क्रिप्ट लिख रहा हूं। वर्तमान में जो एप्लिकेशन मैं बना रहा हूं वह "डेटाबेस ईवेंट" एप्लिकेशन का उपयोग शामिल है। मैं एक subroutine का उपयोग करके एक क्षेत्र के मूल्य निर्धारित करने की कोशिश कर रहा हूँ। जाहिर है, मैं "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 

उत्तर

10

समस्या यह है कि है AppleScript कि काम करेंगे जैसे कुछ करो से database "Folder Cleanup Wizard" या application "Database Events" से tell बी के लिए set_duration का इलाज कर रहा है ताले। (tell ब्लॉक के बाहर, केवल सादा set_duration() काम करेगा।) इसके आसपास जाने के लिए, आपको my set_duration() का उपयोग करने की आवश्यकता है, जो कि ऐप्पलस्क्रिप्ट को फ़ंक्शन के लिए वर्तमान स्क्रिप्ट में देखने के लिए कहता है। तो, इस मामले में, आपके पास

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

मुझे लगता है कि इस वजह से Apple स्क्रिप्ट उलझन में हो रही है जहां set_duration रहता

इस

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} 

मुझे लगता है कि के लिए आप

संबंधित मुद्दे