从AppleScript的路径解压文件扩展名 [英] Extracting File Extensions from AppleScript Paths

查看:209
本文介绍了从AppleScript的路径解压文件扩展名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个脚本苹果最终将标志着从EyeTV的所有iTunes的出口广告。但我跑成一个简单的问题,AppleScript的路径,这EyeTV应用程序返回的记录位置。这里的背景:

 设置为recordingID 370404006
设置身份识别码,以作为recordingID整数
告诉应用程序的EyeTV
    设置eyetvr_file获得记录的ID身份识别码的位置,因为别名
告诉结束
回报eyetvr_file


  

别名麦金塔HD2:文件:EyeTV的存档:南Park.eyetv:000000001613eaa6.eyetvr


现在我需要提取包含路径和文件preFIX 000000001613eaa6(使用<一个href=\"http://stackoverflow.com/questions/4278704/applescript-get-filenames-in-folder-without-extension\">this问题),这样我就可以找相应的商业标记在文件000000001613eaa6.edl。这里的打嗝:

 告诉应用程序发现者
    设置eyetv_path为eyetvr_file的容器
    设置为ROOT_NAME的eyetvr_file名
    设置为FEXT的eyetvr_file扩展名
告诉结束

的结果是,


  

eyetv_path:文档文件南Park.eyetv文件夹的EyeTV归档的磁盘文件夹文档Macintosh的HD2应用发现者


  
  

ROOT_NAME:000000001613eaa6.eyetvr


  
  

FEXT:


FEXT应该是.eyetvr,而不是空字符串。怎样正确地提取从任一eyetvr_file或ROOT_NAME.eyetvr?我已经尝试了一堆黑客像

 设置为FEXT的扩展名(如eyetvr_file文件)

不过,这给喜欢错误,


  

错误不能使别名\\麦金塔HD2:文件:EyeTV的存档:南Park.eyetv:000000001613eaa6.eyetvr \\为类型的文件。 :文件:EyeTV的存档:南Park.eyetv:Macintosh的HD2 000000001613eaa6.eyetvr从别名-1700号文件



解决方案

查找不承认所有的文件扩展名。你可以只使用文本项分隔符,虽然删除最后一部分。

 做shell脚本触摸/tmp/some.file.eyetvr
设置文本项分隔符。
告诉应用程序发现者
    将n设置文件名(POSIX文件/tmp/some.file.eyetvr)
    如果n包含。然后将n设置为文本(THRU的n -2文本项1)
    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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆