Applescript:从显示对话框中打开一个新的 Safari 选项卡

Applescript: Open a new Safari tab from a display dialog box

我想在 Safari 上从带有动态 URL

的显示对话框中打开一个新标签页

基本上只有URL的最后一位在变化,结尾必须来自用户

## dialogue box##
set theResponse to display dialog "Show me the ID" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"

## Open URL##

set myURL to "https://myURL/"
on open location myURL
    set URL to myURL & theResponse
    tell application "Safari" to open URL
end open location

盒子运行完美,我在脚本编辑器中看到结果已被考虑在内:

tell application "Script Editor"
    display dialog "Show me the ID" default answer "" with icon note buttons {"Cancel", "Continue"} default button "Continue"
        {button returned:"Continue", text returned:"123456"}

我只是不确定如何从 2 个不同的来源打开 URL 以及我应该使用什么格式

如果只有几个 URL,您可以只使用按钮,例如`{"Cancel"、"Continue with X"、"Continue with Y"},并根据按钮使用不同的 URL并返回文本。

on run
    set response to (display dialog "Show me the ID" default answer "" with icon note buttons {"Cancel", "Continue with X", "Continue with Y"} default button "Continue with Y")
    if button returned of response is "Continue with X" then
        set baseURL to "https://URLx/"
    else -- Continue with Y
        set baseURL to "https://URLy/"
    end if
    openNewTab(baseURL & text returned of response)
end run

on openNewTab(myURL)
    tell application "Safari"
        activate
        tell window 1 to set current tab to (make new tab with properties {URL:myURL})
    end tell
end openNewTab