I am trying to get a URL via AppleScript, then displaying it as a clickable link via a window. How do I do this? (if I need to use Xcode for this, please add the answer, but provide detailed instructions, please)


3 Answers 3


AppleScript itself cannot display rich text (HTML) in a popup dialog. So your options are:

  1. Display a normal text dialog with AppleScript, showing the URL and asking the user if she wants to go there. If user clicks "OK", open that URL (that's exactly 1 click, so pretty much equivalent to a clickable link).

    -- tested with Safari 5.1.7 on Mac OS X 10.6.8
    set theUrl to "http://j.mp/LgHoEB"
        display dialog theUrl & "\nClick OK to open this URL in Safari." with title "Open URL?" with icon caution
        if button returned of result is "OK" then
            tell application "Safari" to make new document with properties {URL:theUrl}
        end if
    on error number -128 -- user cancelled
        -- do something else
    end try


  2. Use the Safari AppleScript command do JavaScript to make a JavaScript popup with the desired URL as a clickable link (and possibly some more custom HTML):

    -- tested with Safari 5.1.7 on Mac OS X 10.6.8
    set theUrl to "http://j.mp/LgHoEB"
    set JSPopup to "(function() {" & ¬
        "var w = window.open('', 'Clickable link');" & ¬
        "w.document.write(" & ¬
        "'<html><body><p>" & ¬
        "<a href=\"" & theUrl & "\">" & theUrl & "</a>" & ¬
        "</p></body></html>'" & ¬
    tell application "Safari"
        do JavaScript JSPopup in current tab of window 1
    end tell

    Of course, this will only work if your Safari allows popup windows (with my settings, for instance, a new tab is opened instead).


Until now links cannot be made clickable in apple scripts but there can be a way around. For opening a single link, you can use like below,

set theAlertText to "Swiftlint is not installed"
set theAlertMessage to "Download from https://github.com/realm/SwiftLint manually. Would you like to open link?"
display alert theAlertText message theAlertMessage as critical buttons {"Cancel", "Open link"} default button "Open link" cancel button "Cancel" giving up after 60
set the button_pressed to the button returned of the result
if the button_pressed is "Open link" then
    open location "https://github.com/realm/SwiftLint/blob/master/README.md"
end if

tell application "Safari" to display dialog URL of document 1 as string


set theUrl to "http://apple.stackexchange.com/posts/50397"
display dialog theUrl
  • See my updated question...the link needs to be clickable.
    – daviesgeek
    Commented May 3, 2012 at 21:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .