Closing QuickTime by Applescript

♀尐吖头ヾ 提交于 2019-12-12 03:12:37

问题


I am trying to play a movie fullscreen one time, then close the player programmably. I have tried using QTMovieView, command line and AppleScript and found the Applescript is the most simple way.

BUT, as I really don't know Applescript, I can not make the QuickTime auto close after movie playing.

Everything works fine but the "done" was unrecognized in the repeat line. Here is the script with this error:

error "QuickTime Player got an error: Can't make done of document 1 into type specifier." number -1700 from done of document 1 to specifier

tell application "QuickTime Player"
  activate
  open "/Users/...real path of the movie.mov"
  present document 1
  play document 1

  repeat until (get done of document 1)
  end repeat

  delay 2
  close document 1
end tell

Finally, I changed to this, is this ok?

tell application "QuickTime Player"
    quit
end tell
tell application "QuickTime Player"
    activate
    open "/Users/.../...mov"
    tell document 1
        present
        play
        repeat until playing is false
        end repeat
        delay 2
        close
    end tell
    quit
end tell 

New problem: app hang before video finish.


回答1:


This works for me, however it doesn't seem very robust. Is it guaranteed that the current time will always end up being equal to the duration, given that they're both reals? You may want to put some "within epsilon" logic into the repeat condition.

tell application "QuickTime Player"
    play document 1
    repeat until (current time of document 1 = duration of document 1)

    end repeat
    delay 2
    close document 1
end tell



回答2:


Try:

tell application "QuickTime Player"
    tell document 1
        present
        play
        repeat until playing is false
            delay 1
        end repeat
    end tell
quit
end tell


来源:https://stackoverflow.com/questions/10728854/closing-quicktime-by-applescript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!