保持 AppleScript 运行并检查 URL

发布于 2025-01-10 19:13:09 字数 644 浏览 0 评论 0原文

我正在尝试在 macOS 应用程序中创建一个 AppleScript,该应用程序在打开的浏览器运行时运行,并将某些 URL 重定向到特定 URL。这就是它目前的样子:

if \(start) is false then
 error number -128
end if
 repeat until application "Safari" is not running
   if application "Safari" is running then
    tell application "Safari"
      set myList to \(fixedSites) as list
      repeat with theItem in myList
      set (URL of every tab of every window where URL contains theItem) to "https://stackoverflow.com"
   end repeat
  end tell
 end if
end repeat

我在脚本中使用布尔值以使其在用户决定后停止。尽管如此,我的示例的问题是它阻止了我的应用程序(我可以使用系统中的任何其他应用程序,但重复循环似乎过于资源密集型,因为它会提高 CPU 使用率。我尝试过使用空闲/结束也闲置,但这似乎不会触发此脚本。

I'm trying to create an AppleScript in macOS application that is running while the open browser is running and redirecting certain URLs to a specific URL. This is what it looks like at the moment:

if \(start) is false then
 error number -128
end if
 repeat until application "Safari" is not running
   if application "Safari" is running then
    tell application "Safari"
      set myList to \(fixedSites) as list
      repeat with theItem in myList
      set (URL of every tab of every window where URL contains theItem) to "https://stackoverflow.com"
   end repeat
  end tell
 end if
end repeat

I'm using a boolean in the script to make it stop after the user has decided. Still, the problem with my example is that it blocks my application (I can use any other in the system, but it seems that repeat loops are too resource-intensive as it cranks up the CPU usage. I've tried using idle/end idle too, but that doesn't seem to trigger this script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文