我已经在这两天了。 因此,使用Automator和Applescript,我需要扫描一个卷(或卷)并获取每个文件的路径,文件名加扩展名,assetID(如果有),并将每个部分输出到逗号分隔的csv文件。 / p>
到目前为止,我已经整理了Automator动作以及大多数Applescript部分,但我的智慧结束了。路径和文件名有效,但提取assetID(如果有)是问题。并非每个文件都有assetID(以及我不感兴趣的文件)。 assetID始终是一个10位数字,位于文件末尾,前面是下划线(" _"),如下所示 - afilename_1234567890.ext 。就像现在一样,脚本将显示它处理的文件的assetID,但是一旦它到达没有id的文件,我就会看到以下错误,"遇到“运行AppleScript”的操作错误:无法获得#34;"的文本1到-1。“有些事情在某个地方被淹没。
非常感谢任何帮助。
到目前为止的脚本......
运行{input,parameters}
-- save delimiters to restore old settings
set savedDelimiters to AppleScript's text item delimiters
-- set delimiters to delimiter to be used
set AppleScript's text item delimiters to "/"
repeat with aPath in input
-- set a variable to contain the "/" (POSIX) version of the files path
set filesPath to POSIX path of aPath
-- get the file name
set fileName to last text item of filesPath
-- get the file name without the extension
set thePrefix to text 1 thru ((offset of "." in fileName) - 1) of fileName
-- get the asset ID, if there is one
set assetID to rightStringFromRight(thePrefix, "_")
display dialog assetID
if (class of assetID) is integer then
-- get the path only
set pathOnly to ((text items 1 thru -2 of (get POSIX path of aPath)) as Unicode text) & "/"
-- output the path only, file name and asset ID to a comma delimited csv file
display dialog assetID
end if
end repeat
-- restore the old delimiter setting
set AppleScript's text item delimiters to savedDelimiters
结束
on rightStringFromRight(str,del)
local str, del, oldTIDs
set oldTIDs to AppleScript's text item delimiters
try
set str to str as string
if str does not contain del then return str
set AppleScript's text item delimiters to del
set str to str's last text item
set AppleScript's text item delimiters to oldTIDs
return str
on error eMsg number eNum
set AppleScript's text item delimiters to oldTIDs
error "Can't rightStringFromRight: " & eMsg number eNum
end try
end rightStringFromRight
on is_number(number_string) 尝试 将number_string设置为number_string作为数字 返回true 出错了 返回false 结束尝试 结束is_number
答案 0 :(得分:0)
我终于让脚本工作了。纠正了一些错误的假设,一切都很顺利。