V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
0xEEEE
V2EX  ›  macOS

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

  •  
  •   0xEEEE · Jun 16, 2016 · 3137 views
    This topic created in 3603 days ago, the information mentioned may be changed or developed.

    脚本如下

    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 replies    2017-06-14 15:06:02 +08:00
    crayygy
        1
    crayygy  
       Jun 16, 2016
    echo exit?
    zander
        2
    zander  
       Jun 17, 2016
    直接 osascript 不要 tell terminal 。
    allan1st
        3
    allan1st  
       Jun 17, 2016
    试试不要 tell application 直接 `do shell script ("/usr/local/bin/mpv " & theCurrentURL & "&")`
    exxfzc
        4
    exxfzc  
       Jun 14, 2017
    我用 alfred 快捷打开 mpv,观看视频关闭 mpv 后,终端还是依然在,要手动关闭,很麻烦
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5837 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 57ms · UTC 03:08 · PVG 11:08 · LAX 20:08 · JFK 23:08
    ♥ Do have faith in what you're doing.