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

查看:24
本文介绍了通过 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.

推荐答案

这对我有用,但它似乎不是很健壮.是否保证 current time 总是等于 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天全站免登陆