2012-10-16 61 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

相关问题