Applescript 循环遍历 "ls" 和 "do shell script" 的结果
Applescript loop through result of "ls" with "do shell script"
我使用 Applescript 选择了一个文件列表:
set variableName to do shell script "cd /; cd dev/; ls tty.usb*"
当我打印出变量名时,它显示了这个列表:
文件 1
文件 2
从这里开始,我想使用以下方法遍历它们中的每一个:
repeat with theItem in variableName
display dialog theItem
end repeat
不是一一显示 "file1" 和 "file2",而是显示 "f, i, l, e, 1," 等等。
如何循环列表以获得完整的文件名?
感谢您的有用回复!我找到了解决方案。
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
通过使用段落,我可以按换行符拆分并将结果转换为列表。
我使用 Applescript 选择了一个文件列表:
set variableName to do shell script "cd /; cd dev/; ls tty.usb*"
当我打印出变量名时,它显示了这个列表:
文件 1
文件 2
从这里开始,我想使用以下方法遍历它们中的每一个:
repeat with theItem in variableName
display dialog theItem
end repeat
不是一一显示 "file1" 和 "file2",而是显示 "f, i, l, e, 1," 等等。
如何循环列表以获得完整的文件名?
感谢您的有用回复!我找到了解决方案。
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
通过使用段落,我可以按换行符拆分并将结果转换为列表。