It looks like you want a "Launch" action; see Table 8.49 (p. 622) in Section 8.5.3 of the PDF Reference, version 1.6, or Table 8.53 (p. 660) in the same section of version 1.7.
Both versions can be obtained from the Adobe PDF Reference Archive; due to size, version 1.6 (8.8 MiB) might be preferred over version 1.7 (31 MiB). (The ISO standard should be avoided like the plague due to its poor typography.)
It looks like the easiest way to actually use this is to use the pdfLaTeX primitives \pdfstartlink
and \pdfendlink
; see the manual on the pdfTeX page.
Update:
Well, it didn't turn out to be particularly easy, but here is a complete example that almost works for me -- it seems to be interpreted correctly, but fails because (according to Reader) "it is currently disallowed by your system administrator".
(This might seem obvious, but the following is in the "plain" format, not LaTeX -- it's what they call a SpikeSolution.)
Oh, and a warning: I wouldn't suggest testing modifications of this in Adobe's Reader initially; when I tried it on a slightly malformed file, it would forget to close the file when I closed the window, so I would have to close Reader itself before I could re-run TeX. Instead, try it in gsview32, which has the added advantage of giving some sort of diagnostics rather than just not woring.
%&plain
\pdfoutput=1
\pdfcompresslevel=0 % for debuggable PDF output
% taken from http://tex.stackexchange.com/questions/7136/.../7139#7139
{
\catcode`\^0
\catcode`\\12
^gdef^dirsep{\}
}
% This is surprisingly tricky to get right; check the PDF file in a
% text editor to make sure the correct string was output! For example,
% I had {} instead of a space after the \dirsep, and that got copied
% to the output.
\def\figurepath{C:\dirsep figure.bmp}
See the file
\pdfstartlink
attr {/C [0.9 0 0] /Border [0 0 2]}
user {
/Subtype /Link
/A <<
/Type /Action % This is a PDF "Action" dictionary ...
/S /Launch % ... for a "Launch" action
/Win << % Nested dictionary of Windows-only stuff
/F (mspaint) % Application
% Parameters; parens to delimit it as a PDF string, quotes so
% that spaces won't foul things up, and \pdfescapestring to deal
% with any (, ), or \ characters in the path
/P (\pdfescapestring{"\figurepath"})
>>
>>}
{\tt \figurepath}
\pdfendlink
\bye
the pdf link annotation itself can render an underline.
\documentclass[letterpaper, 10pt]{article}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage[breaklinks]{hyperref}
\hypersetup{urlbordercolor=0 0 0,pdfborderstyle={/S/U/W 1}}
\begin{document}
Text: \url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}
\par \end{document}

see also
As requested, using the above to underline or not depending on an outer command:

\documentclass[letterpaper, 10pt]{article}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage[breaklinks]{hyperref}
\hypersetup{urlbordercolor=0 0 0,pdfborderstyle={/W 0}}
\def\uwibble#1{{\hypersetup{pdfborderstyle={/S/U/W 1}}#1}}
\begin{document}
Text: \url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}
Text: \uwibble{\url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}}
Text: \url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}
Text: \uwibble{\url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}}
\end{document}
and...

\documentclass[letterpaper, 10pt]{article}
\usepackage[letterpaper, margin=1in]{geometry}
\usepackage[breaklinks]{hyperref}
\usepackage{ulem}
\hypersetup{urlbordercolor=0 0 0,pdfborderstyle={/W 0}}
\def\uwibble#1{{\xuwibble#1\relax\relax\xxuwibble{#1}}}
\def\xuwibble#1#2\xxuwibble{%
\def\z{[#1][#2]}\show\z
\ifx\url#1%
\hypersetup{pdfborderstyle={/S/U/W 1}}%
\else
\expandafter\uline
\fi}
\begin{document}
Text: \url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}
Text: \uwibble{\url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}}
Text: \url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}
Text: \uwibble{\url{http://test.com/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/uline-text/}}
Text: \uwibble{something not a url} zzzz
\end{document}
Best Answer
You have the two parameters backwards. The correct syntax is:
The first parameter is the url to link to, the second is the text to display.
Also it should be noted that you need to ensure that your PDF viewer is capable of opening a link in a browser.
Code:
Although this question is only about linking to external URLs, one can use
\href
to open other types of files as well. So with the example below (assuming that there exists afoo.pdf
,foo.tex
,foo.png
files in the current directory), and viewing withTeXShop
's PDF viewer, all the files can be opened by clicking on the links.However, with
TeXWorks
and Mac Preview only the web url link works. All the links also work with Acrobat once you accept the security warning.Code: