如何仅在未选中其他URL时使用AppleScript打开URL?

如何仅在未选中其他URL时使用AppleScript打开URL?,applescript,Applescript,我正在寻找解决方案,但我的搜索到目前为止还不太好 这是我的密码 tell application "Google Chrome" if it is running then repeat with t in tabs of windows tell t if URL starts with "https://keep.google.com/" then delay 1

我正在寻找解决方案,但我的搜索到目前为止还不太好

这是我的密码

tell application "Google Chrome"
    if it is running then
        repeat with t in tabs of windows
            tell t
                if URL starts with "https://keep.google.com/" then
                    delay 1
                    activate
                else
                    open location "https://keep.google.com/"
                    delay 1
                    activate
                end if
            end tell
        end repeat
    else
        activate
        open location "https://keep.google.com/"
        delay 1
        activate
    end if
end tell
tell application "Google Chrome" to activate
return ""

我可以检查URL,但是对于每个不是Google Keep的URL,我会打开一个新的URL。所以,如果我有Gmail、Youtube和Keep open,我会打开更多的两个Keep URL如何仅在没有正确URL的情况下打开?

首先,
告诉应用程序“Google Chrome”
,在下面的代码段开始处,如果Google Chrome没有运行,它将启动

tell application "Google Chrome"
    if it is running then
因此,从技术上讲,这不是在下一行中使用
running
属性的正确方法,因为正如您目前编写的那样,Google Chrome总是在
运行时运行,如果它正在运行,则会处理

下面是一个例子,说明我如何重写代码以正确使用
running
属性,并且仅打开目标URL,它还没有打开

示例AppleScript代码:



注意:示例AppleScript代码就是这样,它不采用任何错误处理,仅用于显示完成任务的多种方法之一。用户始终有责任根据需要/需要添加/使用适当的错误处理

像一个魔咒一样工作,一个问题是如果我已经在寻找chrome并且url已经打开,如何更改屏幕以查看url?我现在才意识到,政党不是主要问题。
set theURLsList to {}
set theURL to "https://keep.google.com/"

if running of application "Google Chrome" then
    tell application "Google Chrome"
        repeat with t in tabs of windows
            copy URL of t to end of theURLsList
        end repeat
        if theURLsList does not contain theURL then
            open location theURL
            activate
        end if
    end tell
else
    tell application "Google Chrome"
        open location theURL
        activate
    end tell
end if