目标:识别 macOS 中最近的浏览器窗口,并以 Markdown 链接的形式获取其活动选项卡的 URL 和标题。
它注定要用于从其他应用程序触发的 Alfred 工作流程,但现在我只是在脚本编辑器中调试它的核心。我打开了 Safari 和 Chrome,以及许多其他应用程序。通过调试,我看到它正确列出了所有打开的窗口,但它从不匹配任何一个if
条件。作为进一步的证据,如果我只是tell application
单独使用这些行,就会返回正确的结果。我确信这非常简单。
set output to ""
tell application "System Events"
set appNames to name of every application process whose visible is true
repeat with appName in appNames
if (appName = "Google Chrome") then
using terms from application "Google Chrome"
tell application appName to set currentTabTitle to title of active tab of front window
tell application appName to set currentTabUrl to URL of active tab …
Run Code Online (Sandbox Code Playgroud) applescript ×1