0

实际上,我为 Alfred 开发了一个工作流程。它假设您搜索的任何内容都可以在 Safari 的新私人窗口中打开,并且它按预期工作.. 但问题是,它会在新的私人窗口中打开每个搜索,我希望第一次搜索打开一个新的私人窗口,然后从下一个开始,只是为了在该窗口中打开新标签。希望我足够清楚,我有点新,我会尽力学习,所以非常欢迎任何建议。这是我到目前为止得到的:

tell application "System Events" to ¬
       click menu item "New Private Window" of ¬
        menu "File" of menu bar 1 of ¬
        application process "Safari"
tell application "Safari" to ¬
            set URL of current tab of ¬
        front window to "https://duckduckgo.com/?q={query}&t=h_&ia=web"


tell application "System Events" to ¬
       click menu item "New Tab" of ¬
        menu "File" of menu bar 1 of ¬
        application process "Safari"
tell application "Safari" to ¬
            set URL of current tab of ¬
        front window to "https://duckduckgo.com/?q={query}&t=h_&ia=web"

PS 代码的第 2 部分只是我的草稿,从技术上讲,该部分在窗口内打开一个新选项卡,但只是初始搜索的副本。

4

1 回答 1

1

将私有窗口存储在一个变量中,以便以后可以访问它:

property privyWindow : missing value

tell application "Safari"
    -- a set of tests to make sure the window is present and valid
    set noWindow to (privyWindow is missing value) or not (exists privyWindow) or (current tab of privyWindow is missing value)
end tell
if noWindow is true then
    -- make new private window, and get its first tab
    tell application "System Events"
        tell process "Safari"
            click menu item "New Private Window" of menu "File" of menu bar 1
        end tell
    end tell
    tell application "Safari"
        set privyWindow to first window
        set activeTab to first tab of privyWindow
    end tell
else
    -- retrieve stored window and add a new tab to it
    tell application "Safari"
        set activeTab to make new tab in privyWindow
    end tell
end if

-- open the url in the specified tab
tell application "Safari"
    set URL of activeTab to "https://duckduckgo.com/?q={query}&t=h_&ia=web"
end tell
于 2021-01-12T17:34:33.280 回答