QuickTime Player 的 Applescript 儲存指令

QuickTime Player 的 Applescript 儲存指令

我已經安裝了佩里安插件對於 Quicktime,它可以打開 .flv 文件,然後我可以將它們另存為 .m4v 或 .mov。我正在嘗試使用 Applescript 自動從 .flv 轉換為 .m4v本教程並屠殺他們範例 Applescript 文件,它通常將 ChemDraw 檔案(.cdx、.cml、.mol)轉換為 .tiff,以便它使用 Quicktime 將 .flv 檔案另存為 .m4v。但是,當我嘗試使用它時,出現錯誤「QuickTime Player 出現錯誤:文件 1 無法理解儲存訊息」。我的保存訊息目前是:

將 target_path 中的第一個文件儲存為“.m4v”

看起來像是 QuickTime 字典的說明:

節省說明符:要儲存的文件或視窗。

[作為可儲存的文件格式]:要使用的文件格式。

我也嘗試過“m4v”,沒有句點,但仍然收到錯誤。
我的保存方向是否錯誤,或者可能是嘗試使用 Quicktime 而不是原始 ChemDraw 時出現的錯誤?我嘗試將 .cdx、.cml、.mol、.tiff 和 ChemDraw 的引用分別更改為 .flv、.m4v 和 QuickTime,但也許比這更複雜?

答案1

這個答案太長了,因為您的評論似乎表明您的主要興趣是 AppleScript 本身,而不是將影片從 FLV 轉換為 MP4。如果是這種情況,我強烈建議從一個好的開始AppleScript 參考,仔細閱讀並學習使用可用的工具(特別是腳本編輯器和應用程式字典)。嘗試透過修改現有應用程式來學習新語言不利於除錯,並且可能會導致非常糟糕的結果,例如貨物崇拜編程。也就是說,


我先打開 QuickTime Player 的字典(文件->打開字典...在腳本編輯器中)查看有哪些命令可用。在我的 QuickTime Player 版本 (7.6.4) 中, exportQuickTime Player Suite 中有一個指令:

出口 v :將電影或曲目匯出到文件

   出口參考:要匯出的電影或曲目
   文件:目標文件
   作為AIFF/Apple TV/AVI/BMP/DV 串流/快速啟動 QTVR 電影/FLC/提示
      影片/影像序列/幀間壓縮 VR 物件影片/iPhone/
      iPhone 行動網路/iTunes/MuLaw/MPEG2/MPEG4/圖片/QuickTime 媒體
      連結/QuickTime 影片/QuickTime TeXML/標準 MIDI/System 7 聲音/
      text file/ThreeGPP/wave :所需的文件類型
   [使用預設設定/最近設定]:導出設定
      使用
   [使用預設設定string] :導出設定的名稱
      預設使用
   [使用設定file] :包含匯出設定的文件
   [替換boolean] : 是否應該先刪除原始檔案?

谷歌搜尋一下表明「iPhone」文件類型指的是 .m4v 文件,因此第一步可能是將 .m4v 文件替換save first document in target_path as ".m4v"為.m4v 文件export first document to target_path as iPhone。不過,再查一下字典,就會發現還有一個can export指令:

可以匯出 v :決定電影或曲目是否可以匯出到所需的位置
   類型

   可以匯出參考:要匯出的電影或曲目
      作為AIFF/Apple TV/AVI/BMP/DV 串流/快速啟動 QTVR 電影/FLC/提示
         影片/影像序列/幀間壓縮 VR 物件影片/iPhone/
         iPhone 行動網路/iTunes/MuLaw/MPEG2/MPEG4/圖片/QuickTime 媒體
         連結/QuickTime 影片/QuickTime TeXML/標準 MIDI/System 7 聲音/
         text file/ThreeGPP/wave :所需的文件類型
      → boolean : 是否支援導出

因此,我們應該在實際執行操作之前檢查是否可以以 iPhone/.m4v 格式匯出影片:

if (can export first document as iPhone) then
   export first document to target_path as iPhone
else
   error "Cannot export " & (source_file as string) & " in .m4v (iPhone) format."
end if

但是,如果我們停在這裡,我們可能會注意到某些輸出檔案在超過某個點後無法正確播放,因為 QuickTime 可以非同步載入檔案(即不是一次全部載入)。我們應該嘗試檢查 QuickTime Player 是否已完成載入電影在我們告訴它導出之前;透過檢查字典中列出的載入狀態的完整清單並假設每部電影最終都處於完成狀態或錯誤狀態,我們可以相對輕鬆地添加它。

set error_states to {load state unknown, load error}
set successful_states to {loaded, complete}
repeat until load state of first document is in (error_states & successful_states)
   delay 0.1
end repeat

if (load state of first document is in successful_states) then
   if (can export first document as iPhone) then
      export first document to target_path as iPhone
   else
      error "Cannot export " & (source_file as string) & " in .m4v (iPhone) format."
   end if
else
   error "File is not in a successful load state: " & (load state of first document as string)
end if

答案2

您始終可以訴諸 UI 腳本。以@Benny的答案為基礎,以下是有效的(在某種程度上):

set infile to choose file with prompt "select file:"
set outfile to "filename"

try
    tell application "QuickTime Player"
        activate
        close every window
        open infile
        delay 2 # wait for the document to open
        tell application "System Events"
            keystroke "s" using {command down, shift down} # press Cmd-Shift-S
            delay 1 # wait for the sheet
            keystroke outfile # the filename
            key code 36 # press enter
        end tell
        close document 1 saving no
    end tell
end try

如果您只想TextEdit根據您的評論保存某些內容,您可以使用以下內容作為基礎:

set infile to choose file with prompt "select file:"
set outfile to choose file name with prompt "Save altered file here:"

tell application "TextEdit"
    activate
    open infile
    tell application "System Events" # just some keystrokes for edits
        keystroke "AppleScript was here!"
        key code 36 # press enter
    end tell
    tell document 1 to save in outfile
    close every document saving no
end tell

如果您想將文件儲存為特定文件類型,則該參數似乎有問題as:我無法將其儲存為一種可選格式。您可以透過指定所需的檔案副檔名來規避該問題,例如filename.htmlfilename.odt網頁開放文件分別為格式。

答案3

這裡描述的 Applescript 腳本可能有用:QuickTime 匯出 Droplet

雖然這並不能回答您的問題,但這裡有兩個商業產品似乎是一個解決方案,並且可以進行試用:

Wondershare iPad 影片轉換器 Mac 版(25 美元)
Mac 視訊轉換器(39 美元)

答案4

我不知道這是否有效,但嘗試一下

set infile to choose file with prompt "select file:"
set outfile to choose file name with prompt "Save altered file here:"

try
tell application "QuickTime Player"
activate
close every window
open infile
set dimensions of document 1 to {720, 400}
tell document 1
save self contained file outfile
end tell
-- save document 1 given «class dfil»:file outfile, «class savk»:self contained
close document 1 saving no
end tell
end try

看看是否有效。

如果這不起作用,請參閱此頁面。http://discussions.apple.com/thread.jspa?threadID=1055811

相關內容