AppleScript 新手

New to applescript

本质上,我想要完成的是我想进入一个包含我所有灯塔文件夹的特定目录。我想遍历 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