Learning AppleScript 我正在尝试练习,我想看看我是否可以在 .xhtml
中获得一个类的计数。文件。
在我的 BBEdit 元素中,我为元素设置了一个变量:
set this_project to file of project document 1
确保以所有 .xhtml
为目标文件:
set total_xhtml to {search mode:grep, case sensitive:false, match words:false, extend selection:false, returning results:true, filter:{ID:"111232452", filter_mode:and_mode, filter_terms:{{operand:"xhtml", field:«constant ****FnSf», operator:op_is_equal}}}}
但是当我尝试计算每个文件的类别时,我感到很困惑..
我试过:
set varCount to count class=\"foobar\"" of (this_project in total_xhtml)
如果我尝试 set varCount to count class=\"foobar\""
它在 AppleScript 编辑器中返回一个数字,但我如何才能获得元素中每个文件的完整计数?
最佳答案
如果我理解你的问题,你想知道你的类在不同的 .xhtml 文件中列出了多少次。
如果这就是您想要完成的,下面是一个工作示例,它应该可以满足您的要求。
on run
try
set foundItems to do shell script "grep -ri 'yourClassName' " & quoted form of "/Path/to/Your/directory"
on error
set foundItems to ""
end try
set oldDelims to AppleScript's text item delimiters -- save their current state
set AppleScript's text item delimiters to {return} -- declare new delimiters
set tempList to every text item of foundItems
set AppleScript's text item delimiters to oldDelims -- restore them
set foundCount to count of tempList
end run
关于css - 如何使用 AppleScript 获取类的计数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24615729/