Directory 从AppleScript路径提取文件扩展名

Directory 从AppleScript路径提取文件扩展名,directory,applescript,filenames,filepath,file-extension,Directory,Applescript,Filenames,Filepath,File Extension,我正在编写一个苹果脚本,最终将为所有从EyeTV导出的iTunes制作商业广告。但我在AppleScript路径上遇到了一个简单的问题,EyeTV应用程序将其作为录制位置返回。以下是上下文: 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 a

我正在编写一个苹果脚本,最终将为所有从EyeTV导出的iTunes制作商业广告。但我在AppleScript路径上遇到了一个简单的问题,EyeTV应用程序将其作为录制位置返回。以下是上下文:

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
别名“Macintosh HD2:Documents:EyeTV存档:South Park.EyeTV:00000000 1613EAA6.eyetvr”

现在我需要提取包含路径和文件前缀00000000 1613EAA6(使用),以便在文件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_路径:应用程序“Finder”的磁盘“Macintosh HD2”的文件夹“eyetv存档”的文档文件“South Park.eyetv”

根目录名称:“00000000 1613EAA6.eyetvr”

fext:“”

fext应该是“.eyetvr”,而不是空字符串。如何从eyetvr\u文件或根目录名称中正确提取“.eyetvr”?我试过很多类似的方法

set fext to name extension of (eyetvr_file as document)
但这会产生这样的错误

“无法将别名”Macintosh HD2:Documents:EyeTV存档:South Park.EyeTV:00000000 1613EAA6.eyetvr\“转换为类型文档时出错。别名“Macintosh HD2:Documents:EyeTV存档:South Park.EyeTV:00000000 1613EAA6.eyetvr”中的编号-1700转换为文档


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

迷你评论显然不允许发布代码,因此以下是我对Lauri Ranta的优秀解决方案的编辑:

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

完成该项目后,我将发布一个指向iOS版EyeTV商业标记脚本的链接。

谢谢!这与下面的编辑完美结合,提供了一个比我链接的更好的解决方案。这段代码给了我一个错误,除非我指定了“AppleScript的文本项分隔符”,并且我还保存了以前的设置,以便在更大的代码块中使用:“将delims设置为AppleScript的文本项delims
将AppleScript的文本项分隔符设置为”。
…将AppleScript的文本项分隔符设置为delims”以下是指向生成的AppleScript ExportDone.scpt的链接: