我想从带有动态 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 以及我应该使用什么格式
如果只有几个 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
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句