如果没有选中其他URL,那么如何使用AppleScript打开URL是正确的?

时间:2018-04-17 14:08:28

标签: 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
                    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 ""

我可以检查网址,但对于不是Google Keep的每个网址,我会打开一个新网址。因此,如果我打开了Gmail,Youtube和Keep,我会打开更多两个保留网址。 如果没有人是正确的网址,如何打开?

1 个答案:

答案 0 :(得分:1)

首先,代码块开头的以下代码代码段中的tell application "Google Chrome"将启动谷歌浏览器,如果它没有运行

tell application "Google Chrome"
    if it is running then

因此,从技术上讲,这不是在下一行中使用running 属性的正确方法,因为正如您目前编码的那样,Google Chrome始终在{已处理{1}}。

以下是我如何重写代码以正确使用if it is running then 属性并仅打开目标网址的示例它尚未打开。

示例 AppleScript 代码

running

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

相关问题