2016-03-08 110 views
0

我嘗試使用AppleScript自動執行對一堆文件進行小編輯的過程失敗。更具體地講,我想一個腳本,將:嘗試使用AppleScript在Quicktime中打開,修改和保存文件

  1. 打開一個特定的文件在QuickTime
  2. 拆分成指定長度
  3. 保存每個段相同的格式,並與一個單獨的文件片段與原始質量相同。
  4. 關閉文檔

最重要的,我希望腳本的工作原理實質上無助/無人。

以下是我想要做的更多信息:http://hints.macworld.com/article.php?story=20100305070247890

另一位用戶在StackOverflow asked a similar question後面,但建議不起作用。

從一些網上討論,我已經能夠找到,看來蘋果公司拿走了一些的QuickTime 7的功能版本後,我目前使用10.3+

Here's another discussion描述幾乎什麼我正在努力。正如「kryten2」指出的那樣,出口不再適用於QuickTime的新版本。而且,就像「VideoBeagle」一樣,當我嘗試調用save方法時,我會遇到權限錯誤。

VideoBeagle在該頁面上發佈的代碼不適用於我。下面是修改後的版本:

tell application "QuickTime Player" 
    open basefile --argument passed to script when executed 

    set the clipboard to "outputfile" 
    delay (0.25) 
    tell document 1 
     trim from 0 to 60 
     tell application "System Events" 
      tell process "QuickTime Player" 
       keystroke "s" using command down 
       keystroke "v" using command down 
       delay 1 
       keystroke return 
       delay 3 
       #click menu item "Save..." of menu "File" of menu bar 1 
      end tell 
     end tell 

     close saving no 

    end tell 
end tell 

上面的代碼中並打開在QuickTime文件和修剪文件,以正確的長度,但隨後它會在一個新窗口中的文件的未保存副本,關閉原來的,但不保存新文檔。當我試驗延遲並刪除「修剪」功能時,它將顯示保存對話框,但實際上不會保存文件。

是否有人成功設法使用AppleScript和QuickTime保存文件? ...最近?

非常感謝!

回答

0

如果您有QuickTime Pro授權(不是免費的,但非常便宜),最好應該使用QuickTime Player 7的導出功能。要做到這一點,你還需要從蘋果網站下載這個舊的QT版本。它仍然可用,但Apple基本上只推出了讀取功能的QuickTime Player 7。

如果您想堅持使用QuickTime Player(版本7之後),仍然存在已知的腳本編寫問題。解決方法是模擬GUI的一部分,因爲您已經開始做。

下面的腳本要求處理電影文件,爲修改後的視頻定義新的路徑和名稱,從第二個2修剪到第二個6,然後使用GUI界面保存和關閉。我做了很多評論,以確保您可以瞭解和更新您的需求:

-- select file to be processed 
set myVideo to choose file with prompt "Select video to be processed" 

-- set new path and file name 
set newPath to ((path to desktop folder from user domain) as string) & "Test_Folder" 
set PPath to POSIX path of newPath 
set newName to "cutVideo.mov" 

tell application "QuickTime Player" 
activate 
open myVideo 
set myDoc to front document 
trim myDoc from 2 to 6 -- keep only video from second 2 to 6 
end tell 
tell application "System Events" 
tell process "QuickTime Player" 
    keystroke "s" using {command down} 
    delay 0.8 
    keystroke "G" using {command down} -- go to 
    delay 0.8 
    keystroke PPath -- folder path with/and not : 
    delay 0.8 
    keystroke return 
    delay 0.8 
    keystroke newName -- fill file name 
    delay 0.8 
    keystroke return -- ok save dialog 
    delay 0.8 
    keystroke "w" using {command down} -- close window 
end tell 
end tell 
+0

感謝您的回覆,pbell! 我一直不願回到QT7,因爲我發佈的論壇上的用戶在他們的實驗中沒有成功。 模擬GUI似乎是這樣做的一種多毛,有時不一致的方式(但它可能是唯一的方法)。我能夠讓你的代碼工作(謝謝!),但我不得不在修剪後添加延遲...我假設菜單項沒有被足夠快地重新啓用,並且QuickTime不接受「s」擊鍵。 – Matthew

+0

我很高興它解決了您的問題。我嘗試了許多其他方式來避免QT GUI進行保存和導出,但始終失敗。在GUI腳本中,所需的延遲來自硬件速度,操作系統版本以及其他進程在後臺運行。這就是爲什麼設置安全高價值更好.... – pbell

+0

我不得不承認,再玩一小時玩你提供的代碼,我一直無法得到它始終正確執行。我懷疑/認爲是因爲你提到的因素(硬件,流程等)。有時它不會激活QT窗口,因此鍵擊會發送到其他地方(在調整'_seems_以解決此問題之後調用'activate' ..],有時'keystroke newName'不會發生,因此文件被命名作爲「無題」等等。我可能只需要增加延遲大小,並監視新保存的文件在工作。再次感謝! – Matthew