2011-01-23 18 views
6

私はかなり例外的なapplescripterであり、長い間スクリプトを書いています。私が現在作成しているアプリケーションには、「データベースイベント」アプリケーションの使用が関係しています。私はサブルーチンを使ってフィールドの値を設定しようとしています。どうやら、私は "set_durationを続けることができません"と私は何が間違っているか分かりません。現在のソースコードは以下の通りです。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 

答えて

10

問題があることはAppleScriptであるためにそれが動作すると思います。この

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} 

ような何かが住んでいる場所のAppleScriptが混乱してきているためであると思いますtellbのおかげで、set_durationdatabase "Folder Cleanup Wizard"またはapplication "Database Events"という用語で扱っていますロック。 (tellブロックの外側では、ちょうど普通のset_duration()が動作します)。これを回避するには、my set_duration()を使用する必要があります。これはAppleScriptに現在のスクリプトでその機能を調べるよう指示します。この場合、あなたは持っているでしょう

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

私はset_durationが

は、私はあなたが

関連する問題