从 AppleScript 路径中提取文件扩展名 [英] Extracting File Extensions from AppleScript Paths
问题描述
我正在编写一个 Apple 脚本,最终将标记所有从 EyeTV 导出的 iTunes 的商业广告.但是我遇到了 AppleScript 路径的一个简单问题,EyeTV 应用程序将其作为录制位置返回.这是上下文:
设置recordingID为370404006将 myid 设置为 recordID 作为整数告诉应用程序EyeTV"设置 eyetvr_file 以获取记录 id myid 作为别名的位置结束告诉返回 eyetvr_file
<块引用>
别名Macintosh HD2:Documents:EyeTV Archive:South Park.eyetv:000000001613eaa6.eyetvr"
现在我需要提取包含路径和文件前缀 000000001613eaa6(使用 这个问题)所以我可以在文件 000000001613eaa6.edl 中查找相应的商业标记.这是打嗝:
告诉应用程序Finder"将 eyetv_path 设置为 eyetvr_file 的容器将 root_name 设置为 eyetvr_file 的名称将 fext 设置为 eyetvr_file 的扩展名结束告诉
结果是,
<块引用>eyetv_path:应用程序Finder"的磁盘Macintosh HD2"的Documents"文件夹的EyeTV Archive"文件夹中的文件South Park.eyetv"
root_name: "000000001613eaa6.eyetvr"
文本:""
fext 应该是.eyetvr",而不是空字符串.如何从 eyetvr_file 或 root_name 中正确提取.eyetvr"?我已经尝试了一堆像
这样的黑客将 fext 设置为(eyetvr_file 作为文档)的扩展名
但这会产生类似的错误,
<块引用>错误无法将别名\"Macintosh HD2:Documents:EyeTV Archive:South Park.eyetv:000000001613eaa6.eyetvr\"输入类型文档."从别名Macintosh HD2:Documents:EyeTV Archive:South Park.eyetv:000000001613eaa6.eyetvr"到文档的编号 -1700
Finder 无法识别所有文件扩展名.不过,您可以只使用文本项分隔符来删除最后一部分.
做shell脚本touch/tmp/some.file.eyetvr"将文本项分隔符设置为."告诉应用程序查找器"将 n 设置为文件名(POSIX 文件/tmp/some.file.eyetvr")如果 n 包含."然后将 n 设置为(文本项 1 到 -2 of n)作为文本n -- some.file结束告诉
I'm writing an Apple Script that ultimately will mark commercials for all iTunes exports from EyeTV. But I'm running into a simple problem with AppleScript paths, which the EyeTV app returns as recording locations. Here's the context:
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
alias "Macintosh HD2:Documents:EyeTV Archive:South Park.eyetv:000000001613eaa6.eyetvr"
Now I need to extract the containing path and the file prefix 000000001613eaa6 (using this question) so I can look for the corresponding commercial markings in the file 000000001613eaa6.edl. Here's the hiccup:
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
The results are,
eyetv_path: document file "South Park.eyetv" of folder "EyeTV Archive" of folder "Documents" of disk "Macintosh HD2" of application "Finder"
root_name: "000000001613eaa6.eyetvr"
fext: ""
fext should be ".eyetvr", not the empty string. How do I correctly extract ".eyetvr" from either eyetvr_file or root_name? I've tried a bunch of hack like
set fext to name extension of (eyetvr_file as document)
But this gives error like,
error "Can’t make alias \"Macintosh HD2:Documents:EyeTV Archive:South Park.eyetv:000000001613eaa6.eyetvr\" into type document." number -1700 from alias "Macintosh HD2:Documents:EyeTV Archive:South Park.eyetv:000000001613eaa6.eyetvr" to document
Finder doesn't recognize all filename extensions. You could just use text item delimiters to remove the last part though.
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
这篇关于从 AppleScript 路径中提取文件扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!