正在从AppleScript路径提取文件扩展名



我正在写一个苹果脚本,它最终将标记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:文档:EyeTV档案:South Park.EyeTV:0000000001613eaa6.eyetvr">

现在我需要提取包含路径和文件前缀000000001613eaa6(使用这个问题),这样我就可以在文件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:应用程序"Finder"的磁盘"Macintosh HD2"的文件夹"Documents"的文件夹eyetv Archive的文档文件"South Park.eyetv">

root_name:"000000001613eaa6.eyetvr">

fext:">

fext应该是".eytvr",而不是空字符串。如何从eyetvr_file或root_name中正确提取".eyetvr"?我试过很多像这样的黑客

set fext to name extension of (eyetvr_file as document)

但这会产生错误,比如

error"无法将别名\"Macintosh HD2:Documents:EyeTV Archive:South Park.EyeTV:000000000 1613eaa6.eyetvr\"转换为类型文档。"编号-1700从别名"Macintosh HD2:Documents:EyeTV存档:South Park.EyeTV:0000000 1613ea a.eyetvr"转换为文档

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商业标记脚本。

最新更新