Applescript:无法将文件“xx”变为类型&lt; <class fsrf =“”>&gt;

时间:2018-03-12 17:08:00

标签: applescript

我正在努力让脚本工作,能够通过quicktime批量导出.mts格式的视频文件到1080p的.mov文件中。该脚本失败并出现以下错误:“操作”运行AppleScript“遇到错误:”QuickTime Player出错:无法将文件(文档“00000.MTS”)转换为«class fsrf»类型。“”。我认为这与使用文本文件路径有关?注意我对Applescript没有经验,非常感谢任何有助于使这个简单的脚本工作的帮助。目前它在automator即服务中:

on run {inputFiles}
if inputFiles is equal to {} then
    set inputFiles to (choose file with prompt "Select the file(s) to convert:" with multiple selections allowed without invisibles)
end if
open inputFiles
end run

on open droppedItems
tell application "Finder" to set inputFolder to (container of first item of droppedItems) as Unicode text
set outputFolder to (choose folder with prompt "Select output folder:" default location (inputFolder as alias)) as Unicode text

set exportPreset to (choose from list {"Movie", "iPhone", "iPod", "480p", "720p", "1080p"} with prompt "Choose QuickTime Export Preset:") as Unicode text
if exportPreset is equal to "false" then
    return
end if

repeat with currentItem in droppedItems
    repeat until getProcessPercentCPU("CoreMediaAuthoringSessionHelper") is equal to ""
    end repeat

    tell application "Finder" to set fileName to name of currentItem as Unicode text
    set fileName to text 1 thru ((fileName's length) - (offset of "." in ¬
        (the reverse of every character of fileName) as text)) of fileName
    convertFile(currentItem, outputFolder & fileName & ".mov", exportPreset)
end repeat
end open

on convertFile(inputFile, outputFile, exportPreset)

tell application "QuickTime Player"
    set thisMovie to open inputFile
    open for access file thisMovie
    close access file thisMovie
    export thisMovie in (outputFile) using settings preset exportPreset
    close thisMovie
end tell
end convertFile

on getProcessPercentCPU(processName)
do shell script "/bin/ps -xco %cpu,command | /usr/bin/awk '/" & processName & "$/ {print $1}'"
end getProcessPercentCPU

2 个答案:

答案 0 :(得分:1)

尝试更改:

set outputFolder to (choose folder with prompt "Select output folder:" default location (inputFolder as alias)) as Unicode text

为:

set outputFolder to POSIX path of (choose folder with prompt "Select output folder:" default location (inputFolder as alias))

convertFile(currentItem, outputFolder & fileName & ".mov", exportPreset)

为:

set outputFile to POSIX file (outputFolder & fileName & ".mov")
convertFile(currentItem, outputFile, exportPreset)

并移除open for access / close access commands

沙盒应用不喜欢接收open / save命令的路径字符串,但接受alias / POSIX file值可以。 (如果它仍然无法正常工作,那么它还有其他一些问题,但是当您收到文件系统权限错误时,首先要检查它。)

答案 1 :(得分:0)

发生错误是因为thisMovieQuickTime Player的文档引用,并且此类无法转换/强制转换为file system reference(«class fsrf»)。

这就是错误信息所说的

  

无法将文件(文档“00000.MTS”)转换为“class fsrf”类型

标准添加命令open for access无论如何都不支持QuickTime Player个文档。开/关线的目的是什么?

注意:

as Unicode text因为自从macOS 10.5 Leopard以来对字符串的强制已经过时了。它仅与readwrite命令一起使用来处理UTF16编码的文本。只需编写标准AppleScript文本的强制as text即可。在name of currentItem的情况下,无论如何它都是多余的,因为name的类总是text