[英]Applescript loop through result of “ls” with “do shell script”
I have selected a list of files in Applescript using: 我已使用以下命令在Applescript中选择了文件列表:
set variableName to do shell script "cd /; cd dev/; ls tty.usb*"
When I print out variableName, it shows this list: 当我打印出variableName时,它显示以下列表:
file1 文件1
file2 文件2
From here, I want to loop through each of them using: 从这里开始,我想使用以下命令遍历每个对象:
repeat with theItem in variableName
display dialog theItem
end repeat
Instead of showing "file1" and "file2" one by one, it shows "f, i, l, e, 1," and so forth. 与其一一显示“ file1”和“ file2”,不如显示“ f,i,l,e,1”等等。
How can I loop the list to get a complete file name? 如何循环列表以获取完整的文件名?
Thanks for the helpful responses! 感谢您的有用回复! I have found out the solution.
我找到了解决方案。
set variableName to do shell script "find /dev/tty.usb*"
display dialog variableName
set testArray to paragraphs of the variableName
repeat with theItem in testArray
display dialog theItem
end repeat
By using paragraphs, I'm able to split by newline and covert the result into a list. 通过使用段落,我可以按换行符拆分并将结果隐式转换为列表。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.