【问题标题】:How to run an application in "background" or "hide" an application using apple script?如何使用苹果脚本在“后台”或“隐藏”应用程序中运行应用程序?
【发布时间】:2015-09-14 06:37:27
【问题描述】:

我正在尝试启动和隐藏 quicktime 播放器,开始录制我的 iPhone 屏幕一段时间,并使用以下脚本将输出保存在桌面上,文件名为“hello”

on run
    set filePath to (path to desktop as text) & "hello.mov"
    set f to a reference to file filePath

    startVideoRecording(f)

end run

on startVideoRecording(f)

    tell application "QuickTime Player"
        activate
        tell application "System Events"
            keystroke "h" using command down
        end tell
        set newMovieRecording to new movie recording
        set camera to "Prabhu Konchada's iPhone"
        tell newMovieRecording
            set camera to "Prabhu Konchada's iPhone"
            start
        end tell
        delay (10)
        pause
        save newMovieRecording in f
        stop
        close newMovieRecording
    end tell
end startVideoRecording

为了隐藏我试过的快速播放器:

  1. 告诉应用程序“系统事件”告诉进程“QuickTime Player”使用向下命令击键“h”。
  2. 告诉应用程序“Finder” 将进程“QuickTime Player”的可见设置为 false 结束告诉

  3. 告诉应用程序“系统事件” 将 frontProcess 设置为最前面为 true 的第一个进程 将 frontProcess 的可见设置为 false 结束告诉

以上 3 种方法没有达到我的目的,我不希望这个快速时间在我的屏幕上或在我的 DOCK 中可见......

【问题讨论】:

    标签: applescript


    【解决方案1】:
    tell application "System Events"
    set visible of application process "QuickTime Player" to false
    end tell
    

    【讨论】:

    • 虽然此代码可能会回答问题,但提供有关它如何和/或为什么解决问题的额外上下文将提高​​答案的长期价值。
    【解决方案2】:

    将前窗的边界设置为“不可能”的值并删除activate 行

    on run
        set filePath to (path to desktop as text) & "hello.mov"
        set f to a reference to file filePath
    
        startVideoRecording(f)
    
    end run
    
    on startVideoRecording(f)
    
        tell application "QuickTime Player"
            set newMovieRecording to new movie recording
            set bounds of window 1 to {-3000, 0, 100, 100}
            set camera to "Prabhu Konchada's iPhone"
            tell newMovieRecording
                set camera to "Prabhu Konchada's iPhone"
                start
            end tell
            delay (10)
            pause
            save newMovieRecording in f
            stop
            close newMovieRecording
        end tell
    end startVideoRecording
    

    【讨论】:

    • 是的,当然你还需要我在帖子中省略的on run 处理程序
    • 您能否像我尝试使用 on run 处理程序一样编辑您的帖子
    • 我们开始吧。影片被录制并在 10 秒后出现在桌面上。也许问题是camera 属性,它在QT Player 字典中不存在。但是有一个current camera 属性
    • iPhone的摄像头怎么选?
    • 相机属性很好,它确实对我有用。我不想把它放在我的屏幕上或底座上。所以想在后台运行它或在开始录制后隐藏应用程序
    猜你喜欢
    • 1970-01-01
    • 2017-12-26
    • 2016-03-04
    • 1970-01-01
    • 2015-08-17
    • 1970-01-01
    • 2014-01-10
    • 2011-09-11
    相关资源
    最近更新 更多