Applescript:从显示对话框中打开一个新的Safari标签

时间:2019-08-29 15:49:10

标签: applescript

我想从带有动态URL的显示对话框中打开Safari上的新标签

基本上只有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,以及我应该使用哪种格式

1 个答案:

答案 0 :(得分:0)

如果只有几个URL,则可以仅使用按钮,例如`{“ Cancel”,“ Continue X”,“ Continue 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