Open URL in new Safari tab with AppleScript

前端 未结 12 1729
挽巷
挽巷 2020-12-13 12:43

Is it possible to use AppleScript to open a link in a new tab in Safari?

12条回答
  •  半阙折子戏
    2020-12-13 13:17

    It's been a while since a new answer's been posted here. I think this is the optimal way to do this. It will open Safari if it's not open, create a new window if there are no windows open, and add the tab to the current (or newly created) window.

    tell application "Safari"
        activate
        try
            tell window 1 to set current tab to make new tab with properties {URL:theURL}
        on error
            open location theURL
        end try
    end tell
    

提交回复
热议问题