V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
YiYitao
V2EX  ›  macOS

写了一段脚本, mpv 结合 AppleScript 播放在线视频,有问题请教

  •  
  •   YiYitao · 2016-06-16 22:31:00 +08:00 · 2298 次点击
    这是一个创建于 2875 天前的主题,其中的信息可能已经有所发展或是发生改变。

    脚本如下

    property theCurrentURL : ""
    tell application "Google Chrome"
    	set theCurrentURL to URL of active tab of window 1
    	close active tab of window 1
    end tell
    tell application "Terminal"
    	do script "/usr/local/Cellar/mpv/0.17.0/bin/mpv " & theCurrentURL
    end tell
    

    现在能够自动打开当前网页视频在 mpv 播放,然后关闭视频网页。

    需要求助的问题是,每次运行都会打开一个终端窗口,需要手动关闭很繁琐,那么怎样让每次播放完毕或者退出 mpv 时自动关闭本次打开的终端?


    • 想到的解决办法是 AppleScript 判断命令执行情况然后决定是否关闭终端,但是搜了一圈不知道怎么做
    • 或者通过判断 mpv 进程运行情况,决定是否关闭终端,需要延时判断,否则一开始就会执行退出,但感觉遇到缓存时间过久,延时便不适用

    4 条回复    2017-06-14 15:06:02 +08:00
    crayygy
        1
    crayygy  
       2016-06-16 22:40:41 +08:00
    echo exit?
    zander
        2
    zander  
       2016-06-17 00:19:54 +08:00
    直接 osascript 不要 tell terminal 。
    allan1st
        3
    allan1st  
       2016-06-17 00:43:34 +08:00
    试试不要 tell application 直接 `do shell script ("/usr/local/bin/mpv " & theCurrentURL & "&")`
    exxfzc
        4
    exxfzc  
       2017-06-14 15:06:02 +08:00
    我用 alfred 快捷打开 mpv,观看视频关闭 mpv 后,终端还是依然在,要手动关闭,很麻烦
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   819 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 21:35 · PVG 05:35 · LAX 14:35 · JFK 17:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.