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

AppleScript 问题需要帮助。三个程序中 ps , ai , sketch 如果一个启动,则程序 breaktime 启动计时器。否则停止计时器。

  •  
  •   intellectual · 2017-03-29 10:59:05 +08:00 · 1238 次点击
    这是一个创建于 2584 天前的主题,其中的信息可能已经有所发展或是发生改变。

    breaktime 是一个强制休息的 app 。 里面的计时器启动后,时间够了,进入锁屏状态,强行休息。 可以在计时器启动和结束的时候运行 AppleScript 。 网站是http://breaktimeapp.com/

    我不是程序,也不懂 AppleScript 我猜里面的代码实现起来应该是 if esle 就能搞定,问题就是起码中文社区找不到文档。

    我写成这样了,然后卡住了,当然里面的 running 参数是不对的。

        tell application "BreakTime"
        	
        	if application "Sketch" running or application "Adobe Photoshop CC 2017" running or application "Adobe Illustrator" running then
        	else
        		enabled
        	end if
        
        end tell
    

    下面这个是 breaktime 的一个 AppleScript ,循环启动停止计时器

    tell application "BreakTime"
    	
    	if true then
    		
    	end if
    	
    	
    	set enabled to not enabled
    	
    end tell
    

    满好用的,大家可以试试看

    3 条回复    2017-03-30 16:42:14 +08:00
    intellectual
        1
    intellectual  
    OP
       2017-03-29 11:26:44 +08:00
    哎呀错了,第二个 as 没有 if then
    minamike
        2
    minamike  
       2017-03-29 13:01:20 +08:00   ❤️ 1
    repeat
    if application "Sketch" is running or application "Adobe Photoshop CC 2017" is running or application "Adobe Illustrator" is running then
    tell application "BreakTime" to set enabled to true
    else
    tell application "BreakTime" to set enabled to false
    end if
    end repeat

    保存为 application 然后一直开着就可以了
    intellectual
        3
    intellectual  
    OP
       2017-03-30 16:42:14 +08:00
    @minamike 好厉害,编写代码改变世界啊,赞一个
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5513 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 03:38 · PVG 11:38 · LAX 20:38 · JFK 23:38
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.