如何使用苹果脚本在“后台”运行应用程序或“隐藏”应用程序?

Pra*_*ada 3 applescript

我正在尝试启动并隐藏 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
Run Code Online (Sandbox Code Playgroud)

为了隐藏 Quicktime 播放器,我尝试过:

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

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

上述 3 种方法没有达到我的目的,我不希望这个 Quicktime 遍布我的屏幕或在我的 DOCK 中可见......

Cal*_*ion 5

tell application "System Events"
set visible of application process "QuickTime Player" to false
end tell
Run Code Online (Sandbox Code Playgroud)

  • 虽然此代码可以回答问题,但提供有关如何和/或为何解决问题的附加上下文将提高​​答案的长期价值。 (9认同)