通过Applescript关闭QuickTime [英] Closing QuickTime by Applescript

查看:137
本文介绍了通过Applescript关闭QuickTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图一次全屏播放电影,然后以编程方式关闭播放器. 我尝试使用QTMovieView,命令行和AppleScript,发现Applescript是最简单的方法.

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.

但是,由于我真的不了解Applescript,所以我无法在电影播放后自动关闭QuickTime.

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:

错误"QuickTime Player出现错误:无法将文档1归类为类型说明符."从文档1完成到指定者的编号-1700

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.

推荐答案

这对我有用,但是似乎不够健壮.假设它们都是实数,是否保证总是与duration相等?您可能需要在repeat条件中加入一些在epsilon内"的逻辑.

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

这篇关于通过Applescript关闭QuickTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆