想要在Safari的新选项卡中打开用户生成的URL

Want to open user-generated URL in new tab of Safari

本文关键字:用户 URL 选项 Safari 新选项      更新时间:2023-09-26

我刚刚开始使用applescriptt,我想制作一个提示用户输入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

通过将"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