2012-10-16 78 views
2

我正在編寫一個蘋果腳本,最終將爲來自EyeTV的所有iTunes導出標記商業廣告。但是我遇到了AppleScript路徑的一個簡單問題,即EyeTV應用程序返回的記錄位置。這裏的背景:從AppleScript路徑中提取文件擴展名

set recordingID to 370404006 
set myid to recordingID as integer 
tell application "EyeTV" 
    set eyetvr_file to get the location of recording id myid as alias 
end tell 
return eyetvr_file 

別名 「蘋果HD2:文件:EyeTV的存檔:南Park.eyetv:000000001613eaa6.eyetvr」

現在我需要提取包含路徑和文件前綴000000001613eaa6(使用this question),所以我可以在文件000000001613eaa6.edl中查找相應的商業標記。這裏的打嗝:

tell application "Finder" 
    set eyetv_path to container of eyetvr_file 
    set root_name to name of eyetvr_file 
    set fext to name extension of eyetvr_file 
end tell 

的結果是,

eyetv_path:文檔文件 「南Park.eyetv」 文件夾中的 「EyeTV的歸檔」 文件夾盤的 「文檔」 中的 「Macintosh HD2」 應用「發現者」

ROOT_NAME: 「000000001613eaa6.eyetvr」

FEXT: 「」

fext應該是「.eyetvr」,而不是空字符串。如何從eyetvr_file或root_name中正確提取「.eyetvr」?我已經嘗試了一堆黑客像

set fext to name extension of (eyetvr_file as document) 

但是這給喜歡錯誤,

錯誤「無法使別名\」蘋果HD2:文件:EyeTV的存檔:南Park.eyetv: 「000000001613eaa6.eyetvr \」轉換成文檔類型。「編號-1700從別名「Macintosh HD2:Documents:EyeTV Archive:South Park.eyetv:000000001613eaa6.eyetvr」到文檔

回答

1

Finder無法識別所有文件擴展名。你可以使用文本項目分隔符來刪除最後一部分。

do shell script "touch /tmp/some.file.eyetvr" 
set text item delimiters to "." 
tell application "Finder" 
    set n to name of file (POSIX file "/tmp/some.file.eyetvr") 
    if n contains "." then set n to (text items 1 thru -2 of n) as text 
    n -- some.file 
end tell 
+0

謝謝!這適用於下面的編輯,並提供了一個更好的解決方案,我鏈接到一個。除非我指定「AppleScript的文本項目分隔符」,否則此代碼給了我一個錯誤,並且我還保存了以前的設置以用於較大的代碼塊中:「set delims to AppleScript's text item delims
set AppleScript's text item delimiters to」。「
…設置AppleScript的文本項目分隔符以定界「 – stvs

0

迷你意見顯然不允許張貼代碼,所以這裏是我的編輯勞裏·蘭塔的很好的解決方案:

do shell script "touch /tmp/some.file.eyetvr" 
set delims to AppleScript's text item delimiters 
set AppleScript's text item delimiters to "." 
tell application "Finder" 
    set n to name of file (POSIX file "/tmp/some.file.eyetvr") 
    if n contains "." then set n to (text items 1 thru -2 of n) as text 
    n -- some.file 
end tell 
set AppleScript's text item delimiters to delims 

我會發佈一個鏈接EyeTV的商業標記腳本當我完成該項目時,爲iOS提供支持。

+0

下面是由此產生的AppleScript,ExportDone.scpt的鏈接:https://code.google.com/p/etv-comskip/downloads/detail?name=ETVComskip_h264_HD_mods-1.0rc1。拉鍊&能= 2&q = – stvs

相關問題