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



我想用QuickTime播放一个随机的视频文件。我打开视频文件的默认应用程序是VLC,所以我特别想告诉QuickTime Player打开文件,而不是告诉Finder用默认应用程序打开文件。

当我使用"某个文件"来选择一个随机文件作为";告诉应用程序";QuickTime播放器"部分(我认为它只适用于应用程序"Finder"(,所以我最终尝试了一种变通方法,将随机文件复制到特定位置,然后打开该特定位置。

我目前的解决方案:

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位:

无法制作«class docf»"其中一个随机视频.mp4";"cfol类";超时";"cfol类";音乐"cfol类";无备份";"cfol类";桌面";"cfol类";用户名";"cfol类";用户";应用程序的"类sdsk";Finder";转换为integer类型。

脚本的QuickTime Player部分似乎工作正常;我正在努力把剧本的前半部分写出来。

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

以下示例AppleScript代码适用于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

如果您想以文件的特定类型为目标,假设目标文件夹中有各种类别,则使用以下示例AppleScript代码同时将name extension属性设置为与目标application兼容的值:

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

最新更新