使用 AppleScript 告诉 QuickTime 打开一个文件夹中的随机视频文件

Tell QuickTime to open a random video file in a folder with AppleScript

我想使用 QuickTime 播放 运行dom 视频文件。我打开视频文件的默认应用程序是VLC,所以我特意告诉QuickTime Player打开文件,而不是告诉Finder用默认应用程序打开文件。

我 运行 在使用 'some file' 到 select 一个 运行dom 文件作为“告诉应用程序“QuickTime Player””部分的一部分时遇到问题(我假设它只适用于应用程序“Finder”),所以我最终尝试了一种解决方法,涉及将 运行dom 文件复制到特定位置,然后打开该特定位置。

我目前的解决方案:

        tell application "Finder"
            set folderPath to "Macintosh HD:Users:username:Desktop:No Backup:Music:TimeOut:"
            delete (every item of folder folderPath whose name is "video.mp4")
            set sourceFile to some file of folder folderPath
            set duplicateFile to duplicate file sourceFile of folderPath
            set the name of duplicateFile to "video.mp4"
        end tell
        tell application "QuickTime Player"
            set theMovie to open "Macintosh HD:Users:username:Desktop:No Backup:Music:TimeOut:video.mp4"
            tell theMovie
                set the looping of theMovie to true
                set the present of theMovie to true
                play
            end tell
        end tell

这会导致以下错误,突出显示 duplicate file sourceFile of folderPath 位:

Can’t make «class docf» "One of the random videos.mp4" of «class cfol» "TimeOut" of «class cfol» "Music" of «class cfol» "No Backup" of «class cfol» "Desktop" of «class cfol» "username" of «class cfol» "Users" of «class sdsk» of application "Finder" into type integer.

脚本的 QuickTime Player 部分似乎工作正常;我正在尝试编写脚本的前半部分。

如果能提供一点帮助,我们将不胜感激!

以下 示例 AppleScript code 时对我有用folderPath 变量的值是正确的HFS路径:

set folderPath to ¬
    "Macintosh HD:Users:username:Desktop:No Backup:Music:TimeOut:"

tell application "Finder" to ¬
    set the fileToPlayInQuickTime to ¬
        some file of container folderPath as alias

tell application "QuickTime Player"
    set theMovie to open fileToPlayInQuickTime
    tell theMovie
        set the looping of theMovie to true
        set the present of theMovie to true
        play
    end tell
end tell

如果您想要针对 文件 的特定 类型 ,假设有各种 类型 在目标 文件夹 中,然后使用以下 example AppleScript code 同时将 name extension 属性 设置为与目标兼容的 申请:

tell application "Finder" to ¬
    set the fileToPlayInQuickTime to ¬
        (some file of container folderPath ¬
            whose name extension is "mp4") as alias