如何解决Applescript的新手
基本上,我要完成的工作是将CD放入包含所有灯塔文件夹的特定目录中。我想遍历urls.txt的每一行,并对每个URL执行npm lighthouse命令,并将结果输出到CSV中以供以后分析。
do shell script "cd /Users/user/Documents/Lighthouse\\"
set srcFile to "urls.txt"
set lns to paragraphs of (read file srcFile as «class utf8»)
repeat with ln in lns
do shell script "npm lighthouse --throttling-method simulate --verbose --view --emulated-form-factor mobile --output-path "/Users/user/Documents/Lighthouse/LighthouseReports.csv" https://www.aphrodites.com/collections/bestsellers-home/products/tree-of-life-heart-edition-charm-bracelet-with-real-austrian-crystals"
end repeat
有些帮助太棒了,谢谢!
解决方法
以下内容可能会使您更接近一点。至少,对于我要尝试做的事情,它是有效的AppleScript(以前从未使用过灯塔)。我假设您希望do shell script
中的给定URL是存储在文件每一行中的URL,对吧?
quoted form of
命令可确保为UNIX正确引用路径,从而省去了一些麻烦。我使用了npm的完整路径,因为do shell script
不会导入您的交互式shell PATH变量,也不会找到该实用程序。如果您想知道do shell script
是否能够找到实用程序,请运行do shell script "which utilityname"
;如果命令出错,请使用完整路径。
set srcFolder to "/Users/user/Documents/Lighthouse/"
set srcFile to srcFolder & "urls.txt"
set outputPath to quoted form of (srcFolder & "LighthouseReports.csv")
set lns to paragraphs of (read file srcFile as «class utf8»)
repeat with ln in lns
do shell script "/usr/local/bin/npm lighthouse --throttling-method simulate --verbose --view --emulated-form-factor mobile --output-path " & outputPath & " " & quoted form of ln
end repeat
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。