想要在Safari的新标签页中打开用户生成的网址

时间:2012-03-02 19:43:14

标签: javascript url safari applescript

我刚刚开始使用applescript,我想创建一个提示用户输入URL的应用程序。在此之后,应用程序在Safari的新选项卡中打开给定的URL。这就是我所拥有的,但它不起作用。

    tell me
        activate
        set s to display dialog "Which website do you want to open?" default answer "https://www."
    end tell
    tell application "System Events"
        tell application "Safari" to activate
        tell process "Safari"
            click menu item "New Tab" of menu "File" of menu bar 1
        end tell
    end tell

    tell application "Safari"
        set URL of document 1 to "text returned of s"
    end tell

1 个答案:

答案 0 :(得分:1)

附上" s"返回的文字。在引号中,你已经使它成为一个文字字符串,而不是你想要使用的记录属性 - 删除引号将使它工作。您不必编写用户界面脚本来创建选项卡,该命令位于Safari的脚本字典中,例如:

tell me to activate
set s to text returned of (display dialog "Which website do you want to open?" default answer "https://www.")
tell application "Safari"
    activate
    tell window 1
        set current tab to (make new tab)
        set URL of current tab to s
    end tell
end tell