I want to have a person enter times in a text field, and have AS calculate the time difference. I’ve tried dozens of variations to get this working, including those in similiar posts.
It works fine in script editor, but the script fails when it’s time to ‘set the contents of the text field’ to the answer.
Here’s one version of the code I am using:
set startTime1 to "12:00"
set startTime to my date startTime1
set finishTime1 to "6:00"
set finishTime to my date finishTime1
set answer to startTime - finishTime
the script fails with this last line:
set contents of text field “totalHours” to answer
Thank you very much for your ideas!javascript:emoticon(‘:o’)
I’m assuming by your use of a named text field that you’re writing an AppleScript Studio app. The line you’re having trouble with (set contents of text field “totalHours” to answer) might be failing because you’re not targetting it correctly.
You need to use its entire hierarchy to target it so it should look something like:
set contents of text field “totalHours” of window “WindowName” to answer
Also, the value of answer won’t be in hours, but seconds. If you really want to put the total hours in the “totalHours” text field, you’re going to need to divide by 3600 or work with the seconds in some other way.
Also, there is a forum dedicated to AppleScript Studio for further questions of this sort.