Is there any way to find out how much time has elapsed?
  • I'm looking at the scripting interface, and I don't think the scripting dictionary has access to how many times an interval cue has been fired so far.

    I've been able to work around this using script properties, but that's kind of fragile -- if I have to reset the document or something else that prevents the counter from being reset, I have to do it by hand. The goal here is to pop up a notification a certain number of times during the activity to let me know how much time is left. Here's the script I'm using.

    ======

    property timesToFire : 10
    property timesFired : 0

    using terms from application "FlexTime"
    on HandleFlexTimeCue(myDocument, myRoutine)

    if timesFired is not equal to timesToFire then
    set timesFired to timesFired + 1
    else
    set timesFired to 0
    end if


    set activityName to name of myRoutine
    set timeUnits to (base unit of myRoutine as string)
    set timeToRun to numeric duration of myRoutine as integer

    set timeSlice to timeToRun / timesToFire

    set timeLeft to (timeToRun - (timesFired * timeSlice))

    set myMessage to "Time left for " & activityName & ":
    " & timeLeft & " " & (timeUnits as string) & ""

    display message myMessage at screen position top left dismissing after delay 1
    end HandleFlexTimeCue
    end using terms from

    =======

    By the way, the using terms from business was the only way I was able to get the dang thing to compile on 10.4.7 in Script Editor. Am I missing something there?
  • Hmm - it's definitely a shortcoming that the "time remaining" is not somehow exposed through the scripting model. I'm putting this on my list as a high priority bug to be fixed probably in a bug fix release (1.0.2). You workaround certainly doesn't seem ideal, but I'm glad you figured something out :)

    You know, I never had any trouble using th FlexTime terminology in the test cues I played with, but I may have always had Script Editor "primed" to recognize them while I was writing those scripts. What you've discovered is probably, actually, the way I should document it as being done. I'll look into this.

    (I noticed some confusing use of the word "routine" in your script - you are using the name routine to identify the "activity" parameter. No big whoop, but this could get confusing, since the document parameter is actually more representative of the routine as a whole.)

    Daniel
  • (I noticed some confusing use of the word "routine" in your script - you are using the name routine to identify the "activity" parameter. No big whoop, but this could get confusing, since the document parameter is actually more representative of the routine as a whole.)

    I consider my script to be a stopgap until elapsed time is passed in so I can try to do it "for real". Thanks for pointing that out, though. Once I get to the point of actually using something like this for a script cue, I'll make sure I'm using the right terminology, especially if I end up distributing the script. :)
  • And now I see that the nomenclature problem came straight out of my sample script! Silly me... :)

    I'm working on this proper scripting support right now, so the script should be much simplified for the next version of FlexTime.

    Daniel
  • Daniel Jalkut said:
    And now I see that the nomenclature problem came straight out of my sample script! Silly me... :)

    I thought that might have been it, but I didn't want to say anything because I wasn't remotely sure. It's okay, I forgive you. :)
  • I just wanted to wrap this thread up by pointing out that FlexTime 1.0.3 has the scripting support for this built-in. I've also included an example scripted cue called "Encouragement Cue" that makes use of the support to do something very much along the lines of what chellman is describing here.

    For more details check out this blog entry.
  • Hey Daniel,

    I dig the encouragement cue -- thanks for that. Here's another potential wrinkle in it.

    Let's say, entirely unhypothetically, that I've expressed my activities in terms of minutes. Like, 2.5 minutes. Then I want to pop up an encouragement cue that uses different time units (e.g. seconds). I know I can change my activities so they're expressed in seconds, but I'm wondering if there's any way to do this that I'm missing in the current scripting support.
  • Hi Joe - there's nothing you're missing in the scripting support - I didn't add any mechanism for cleverly translating between the units. I will think about whether that seems like a good thing to add for an update. I'm assuming most of the time the string you want will be whatever the "base unit" of the activity is... I am a little bit wary of adding too many little details to the scripting dictionary for fear of it getting too complicated.
  • I understand the desire to avoid complication. The seconds workaround isn't terrible by any means. If I can think of something more clever, I'll let you know.
Start a New Discussion

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!