Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)

share|improve this question

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 ""
        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 ""
    set JSPopup to "(function() {" & ¬
        "var w ='', '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).

share|improve this answer
tell application "Safari" to display dialog URL of document 1 as string


set theUrl to ""
display dialog theUrl
share|improve this answer
See my updated question...the link needs to be clickable. – daviesgeek May 3 '12 at 21:14

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.