从 Apple Compressor 获取最后编码的文件信息
Getting last encoded file information from Apple Compressor
所以我是 AppleScript 的新手,但学到了很多东西。我正在尝试创建一个 AppleScript,让我知道 Apple Compressor 何时完成编码,并通知我它是否成功。我对告诉压缩器何时完成和通知但难以从 Compressor 的历史日志中获取文件名和状态 (complete/fail/cancelled) 感到失望。
最初尝试使用 UI 脚本编写,但 Compressor 的 window 层次结构列表随着每个新编码而变化。所以现在从历史日志中提取它,它位于用户文件夹“Library/Application Support/”文件夹中,如下所示:
然后,文件本身在文件底部附近包含状态(成功或失败),如下所示:
所以对如何 A) 找到最后一个文件及其名称,以及 B) 获取文档中最后一个“ElementStatusState”的值感到困惑。
这是我开始的地方,但在尝试解析文件夹路径时遇到错误:
tell application "Finder"
set latestFile to (last item of (sort (get files in folder "~/Library/Application Support/Compressor/History/V4" of application "System Events") by name)) as text
set fileName to latestFile's name
end tell
这段代码抛出一个错误,关于无法将其转换为预期的文件类型,而且,我可以看到它正在抓取一个不是最后修改的文件。
最后我想要 2 个变量,它们是 1) theFileName = 即编码电影的名称,以及 2) theStatus = 即编号 4,5 或 6)
有什么想法吗?
您需要执行类似以下脚本的操作。该脚本找到最近修改过的文件,然后深入 plist 文件以找到各种状态编号,以及它们登录的记录的名称。我假设 Compressor 生成的每个文件都具有相同的结构;如果没有,您可能会发现必须更改脚本。但这应该让您了解如何做到这一点。
名称和状态值按深度顺序存储在 nameList
和 valueList
变量中。
set filePath to POSIX file "~/Library/Application Support/Compressor/History/V4"
-- sort the file list by modification date, then get the last item.
tell application "Finder"
set mostRecentFile to last item of (sort files of folder filePath by modification date) as alias
end tell
set mostRecentFilePath to POSIX path of mostRecentFile
set nameList to {}
set valueList to {}
tell application "System Events"
set plistFile to property list file mostRecentFilePath
tell plistFile
tell (first property list item whose kind is record)
copy value of property list item "ElementInfoName" to end of nameList
copy value of property list item "ElementStatusState" to end of valueList
tell (first property list item whose kind is list)
tell (first property list item whose kind is record)
copy value of property list item "ElementInfoName" to end of nameList
copy value of property list item "ElementStatusState" to end of valueList
tell (first property list item whose kind is list)
tell (first property list item whose kind is record)
copy value of property list item "ElementInfoName" to end of nameList
copy value of property list item "ElementStatusState" to end of valueList
end tell
end tell
end tell
end tell
end tell
end tell
end tell
所以我是 AppleScript 的新手,但学到了很多东西。我正在尝试创建一个 AppleScript,让我知道 Apple Compressor 何时完成编码,并通知我它是否成功。我对告诉压缩器何时完成和通知但难以从 Compressor 的历史日志中获取文件名和状态 (complete/fail/cancelled) 感到失望。
最初尝试使用 UI 脚本编写,但 Compressor 的 window 层次结构列表随着每个新编码而变化。所以现在从历史日志中提取它,它位于用户文件夹“Library/Application Support/”文件夹中,如下所示:
然后,文件本身在文件底部附近包含状态(成功或失败),如下所示:
所以对如何 A) 找到最后一个文件及其名称,以及 B) 获取文档中最后一个“ElementStatusState”的值感到困惑。
这是我开始的地方,但在尝试解析文件夹路径时遇到错误:
tell application "Finder"
set latestFile to (last item of (sort (get files in folder "~/Library/Application Support/Compressor/History/V4" of application "System Events") by name)) as text
set fileName to latestFile's name
end tell
这段代码抛出一个错误,关于无法将其转换为预期的文件类型,而且,我可以看到它正在抓取一个不是最后修改的文件。
最后我想要 2 个变量,它们是 1) theFileName = 即编码电影的名称,以及 2) theStatus = 即编号 4,5 或 6)
有什么想法吗?
您需要执行类似以下脚本的操作。该脚本找到最近修改过的文件,然后深入 plist 文件以找到各种状态编号,以及它们登录的记录的名称。我假设 Compressor 生成的每个文件都具有相同的结构;如果没有,您可能会发现必须更改脚本。但这应该让您了解如何做到这一点。
名称和状态值按深度顺序存储在 nameList
和 valueList
变量中。
set filePath to POSIX file "~/Library/Application Support/Compressor/History/V4"
-- sort the file list by modification date, then get the last item.
tell application "Finder"
set mostRecentFile to last item of (sort files of folder filePath by modification date) as alias
end tell
set mostRecentFilePath to POSIX path of mostRecentFile
set nameList to {}
set valueList to {}
tell application "System Events"
set plistFile to property list file mostRecentFilePath
tell plistFile
tell (first property list item whose kind is record)
copy value of property list item "ElementInfoName" to end of nameList
copy value of property list item "ElementStatusState" to end of valueList
tell (first property list item whose kind is list)
tell (first property list item whose kind is record)
copy value of property list item "ElementInfoName" to end of nameList
copy value of property list item "ElementStatusState" to end of valueList
tell (first property list item whose kind is list)
tell (first property list item whose kind is record)
copy value of property list item "ElementInfoName" to end of nameList
copy value of property list item "ElementStatusState" to end of valueList
end tell
end tell
end tell
end tell
end tell
end tell
end tell