Answers:
这是一个简单的例子,如果文件夹为空(返回0)也可以工作:
第一个shell脚本是:
wc -l
第二是:
sed -e's / // g'
第一个脚本计算行数,第二个脚本删除不必要的空格。
在AppleScript中:
local nitems
tell application "Finder" to set nitems to count of items in folder "mress HD:Users:allbery:Desktop"
set the clipboard to (nitems as Unicode text)
Finder仍然使用碳式路径,如上所示; 转换需要一些愚蠢的东西
local nitems
local fpath
tell application "System Events" to set fpath to path of disk item "/Users/allbery/Desktop"
tell application "Finder" to set nitems to count of items in folder fpath
set the clipboard to (nitems as Unicode text)
tell application "Finder" to set nitems to count of items in folder (POSIX file "/Users/danielbeck/Desktop")
as alias
,正如我所期待的那样。