从AppleScript路径提取文件扩展名 [英] Extracting File Extensions from AppleScript Paths
问题描述
将recordingID设置为370404006
将myid设置为记录ID为整数
告诉应用程序EyeTV
设置eyetvr_file来获取记录id myid的位置作为别名
end tell
return eyetvr_file
别名Macintosh HD2:文件:EyeTV档案:South Park.eyetv:000000001613eaa6.eyetvr
现在我需要提取包含的路径和文件前缀000000001613eaa6(使用这个问题),所以我可以在文件000000001613eaa6.edl中查找相应的商业标记。这是打嗝:
告诉应用程序Finder
将eyetv_path设置为eyetvr_file的容器
将root_name设置为eyetvr_file的名称
将fext设置为eyetvr_file的名称扩展名
end tell
结果是,
eyetv_path:磁盘Macintosh文件夹Documents的文件夹EyeTV Archive的文件夹SouthTV.eyetv HD2应用程序Finder
root_name:000000001613eaa6.eyetvr
fext: p>
fext应为.eyetvr,而不是空字符串。如何从eyetvr_file或root_name正确提取.eyetvr?我试过一堆黑客,如
将fext设置为(eyetvr_file作为文档)的名称扩展名
但是这样就会出现错误,如
错误不能使别名\Macintosh HD2:文件:EyeTV存档:South Park.eyetv:000000001613eaa6.eyetvr\转换为类型文档。号码-1700从别名Macintosh HD2:Documents:EyeTV Archive:South Park.eyetv:000000001613eaa6.eyetvr到文件
Finder无法识别所有文件扩展名。您可以使用文本分隔符来删除最后一部分。
执行shell脚本触摸/tmp/some.file。 eyetvr
将文本分隔符设置为。
告诉应用程序Finder
将n设置为文件名(POSIX文件/tmp/some.file.eyetvr)
如果n包含。然后将n设置为(文本1到n的n)作为文本
n - some.file
end tell
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屋!