4 Replies Latest reply: Jan 21, 2013 7:01 AM by A.P.M. Wülfinghoff
A.P.M. Wülfinghoff Level 1 Level 1 (5 points)

After updating to Mountain Lion I experienced some problems with the AppleScript scripts I use in a Filemaker Pro environment.

This necessitated me to change from QTP to QTP 7.

The following script reflects the FMP environment; when I try to abstract from the FMP environment, I encounter other problems.

 

tell application "QuickTime Player 7" to launch

--------------------------------------------------------------

tell application "FileMaker Pro"

  activate

          set url_path to cell "bestandspad" of current record

end tell

 

set tekst to ""

--------------------------------------------------------------------------------

tell application "QuickTime Player 7" to getURL url_path

 

delay 0.1

tell application "System Events"

          set visible of process "QuickTime Player 7" to false

          repeat until visible of process "QuickTime Player 7" is false

          end repeat

end tell

 

 

tell application "QuickTime Player 7" to set doc1Exists to (exists document 1)

if not doc1Exists then

          set tekst to "next"

else

          tell application "QuickTime Player 7" to play document 1

end if

 

set the clipboard to tekst

 

set tekst to ""

--------------------------------------------

repeat

          display dialog "Interrupt" buttons {"Stop", "Pauze"} giving up after (my secLeft())

          set {b, fin} to {button returned, gave up} of result

          if fin then exit repeat

          if b = "Stop" then

                    set tekst to "Stop"

                    exit repeat

          else

                    tell application "QuickTime Player 7" to pause document 1

                    display dialog "Verder gaan ?" with title "" buttons {"Stop", "Hervat"} default button 2

                    set b to button returned of result

                    if b = "Hervat" then

                              tell application "QuickTime Player 7"

                                        tell document 1

                                                  if duration = current time then exit repeat

                                                  play

                                        end tell

                              end tell

                    else

                              set tekst to "Stop"

                              exit repeat

                    end if

          end if

end repeat

 

set the clipboard to tekst

 

on secLeft()

          tell application "QuickTime Player 7"

                    tell document 1

                              set d to (duration - current time)

                    end tell

          end tell

          set d to round d rounding up

          if d < 1 then set d to 1

          return d

end secLeft

------------------------------------------------------------------------

tell application "QuickTime Player 7" to close document 1 saving no

tell application "QuickTime Player 7" to quit

 

 

Everything works fine, but.

The problem is with the 'display dialog ... giving up after (my secLeft())'

This is supposed to return fin=true when current time equals duration or when my secLeft=0; it always returns fin=false

This program runs fine on the AppleScript editor; 'current time' sometimes poses a problem in other programs.

Any idea how to correct 'dispaly dialog (without moving back to QTP)?


iMac, OS X Mountain Lion (10.8.2), FileMaker Pro 11
  • 1. Re: display dialog ... giving after integer
    A.P.M. Wülfinghoff Level 1 Level 1 (5 points)

    To induce you to a response I submit the program in a simplified form, so that you can run it in the AppleScript editor after copying; you only have to fill in the url_path.

     

    tell application "QuickTime Player 7" to launch

    --------------------------------------------------------------

    set url_path to "/Users/your name/Desktop/song title.mp3"

    set tekst to ""

    --------------------------------------------------------------------------------

    tell application "QuickTime Player 7" to open url_path

     

    tell application "QuickTime Player 7" to set doc1Exists to (exists document 1)

    if not doc1Exists then

              set tekst to "next"

    else

              tell application "QuickTime Player 7" to play document 1

    end if

     

     

    set the clipboard to tekst

     

     

    set tekst to ""

    --------------------------------------------

    repeat

              display dialog "Interrupt" buttons {"Stop", "Pause"} giving up after my secLeft()

              set {b, fin} to {button returned, gave up} of result

              if fin then exit repeat

              if b = "Stop" then

                             set tekst to "Stop"

                             exit repeat

              else

                             tell application "QuickTime Player 7" to pause document 1

                             display dialog "Continue ?" with title "" buttons {"Stop", "Resume"} default button 2

                             set b to button returned of result

                             if b = "Resume" then

                                                 tell application "QuickTime Player 7"

                                                           tell document 1

                                                                     if duration = current time then exit repeat

                                                                          play

                                                           end tell

                                                end tell

                             else

                                            set tekst to "Stop"

                                             exit repeat

                             end if

    end if

    end repeat

     

    set the clipboard to tekst

     

    on secLeft()

              tell application "QuickTime Player 7"

                        tell document 1

                                  set d to (duration - current time)

                        end tell

              end tell

              set d to round d rounding up

              --if d < 1 then set d to 1

              return d

    end secLeft

    ------------------------------------------------------------------------

    tell application "QuickTime Player 7" to close document 1 saving no

    tell application "QuickTime Player 7" to quit

     

    It seems, that 'repeat' is not working. The value of secLeft() is not refreshed while playing.

    I tried repeat while and repeat until, but to no avail.

    Comment please.

  • 2. Re: display dialog ... giving after integer
    twtwtw Level 5 Level 5 (4,690 points)

    firt thing to try is breaking up the complex command into simpler parts:

     

              set s to secLeft()

      display dialog "Interrupt" buttons {"Stop", "Pauze"} giving up after s


    giving up after expects a simple integer, and may be getting confused at being fed a handler.

     

    see if that works.

  • 3. Re: display dialog ... giving after integer
    A.P.M. Wülfinghoff Level 1 Level 1 (5 points)

    Thanks for your suggestion, but unfortunately it doesn't make any difference.

    The script used to work without any problem, until I updated from OS Lion to OS Mountain Lion.

  • 4. Re: display dialog ... giving after integer
    A.P.M. Wülfinghoff Level 1 Level 1 (5 points)

    I don't care for the points, but I have indicate that the problem is solved.

    If it interests you, apparently since or as some result of Mountain Lion, the time measured for the duration of a song in the Applescript was no longer in seconds, but in milliseconds times 0.6; this means that a 3 minute song became 180 * 1000 * 0.6 = 108000.

    Initially I didn't notice, as iTunes works also in milliseconds; the fixed factor of 0.6 I took for granted.

    SecLeft() returned values of several tens of thousands, 'giving up after' was slowly counting in real seconds.

    So the program functions as it should, only the time values were mixed up.