Open URL in new Safari tab with AppleScript

前端 未结 12 1737
挽巷
挽巷 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:28

    I found a way to open a new tab in the background with Safari.

    tell application "Safari"
    
    set the URL of (make new tab in window 1) to "your.url.net"
    
    end tell
    

    During the time I wrote this answer I made this

    tell application "Safari"
    
    try
    
        display dialog "Website URL" default answer "" buttons {"OK", "Annuler"} default button 1
    
        set theURL to text returned of result
    
        set netProto to "https://"
    
        if theURL contains netProto then
    
            set the URL of (make new tab in window 1) to theURL
    
        else
    
            set the URL of (make new tab in window 1) to netProto & theURL
    
        end if
    
    end try
    
    end tell
    

    New version

    tell application "Safari"
    
    repeat
    
        try
    
            display dialog "Website URL" default answer "" buttons {"OK", "Annuler"} default button 1
    
            set theURL to text returned of result
    
            if theURL is "" then exit repeat
    
            set netProto to "https://"
    
            if theURL contains netProto then
    
                set the URL of (make new tab in window 1) to theURL
    
            else
    
                set the URL of (make new tab in window 1) to netProto & theURL
    
            end if
    
            display dialog "Do you want to open a new tab?" buttons {"Yes", "No"} default button "Yes"
    
            if button returned of result is "No" then exit repeat
    
        end try
    
    end repeat
    
    end tell
    

    Any suggestions will be appreciate

    Best regards

提交回复
热议问题