Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

An AppleScript to automate HTML link construction Internet
I often want to include an HTML link to a page in stuff I put on the web, so I developed the following AppleScript. It takes a URL off of the clipboard and auto-builds the link HTML and then places that HTML on the clipboard. To use, first put the URL on the clipboard (select the URL and copy it), then run the script. Finally, paste the link HTML into your blog, email, etc. Here's the AppleScript:
set the_url to the clipboard
set the_text to "<a href="" & the_url 
 & ""target=_blank>here</a>"
set the clipboard to the_text
Save this as an AppleScript application, and then put it wherever it's easiest for you to run -- I put it into my AppleScript utility menu. When you paste the link HTML into a document, the link will look like this: here. If you want to control the link text to say something other than "here," then read on for an alternative script.

This version will prompt you for the link text each time you use it:
set the_url to the clipboard
set temp to display dialog 
 "Please enter the link text" default answer "here"
set link_text to text returned of temp
set the_text to "<a href="" & the_url 
 & "" target=_blank>" & link_text & "</a>"
set the clipboard to the_text
[robg adds: These worked as described, and using something like Butler, QuicKeys, or any of a dozen other utilities, you could bind it to a hotkey for extra easy access. As an alternative, I use a simple TypeIt4Me expansion to create HTML links: %| -- the tells TypeIt4Me to paste the clipboard contents (the URL), and then %| positions the cursor at that location. So I copy a URL, type my shortcut (I use hhref) in the destination app, and then type the text for the link. I use this literally dozens of times a day for hints postings and Macworld blogs.]
    •    
  • Currently 1.88 / 5
  You rated: 3 / 5 (8 votes cast)
 
[7,698 views]  

An AppleScript to automate HTML link construction | 6 comments | Create New Account
Click here to return to the 'An AppleScript to automate HTML link construction' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
An AppleScript to automate HTML link construction
Authored by: NovaScotian on May 10, '07 09:52:53AM
The second form needs a few escapes for the quotes before and after the URL:
set the_url to the clipboard
set temp to display dialog 
	"Please enter the link text" default answer "here"
set link_text to text returned of temp
set the_text to "<a href=\"" & the_url 
	& "\"" & " target=_blank>" & link_text & "</a>"
set the clipboard to the_text


[ Reply to This | # ]
An AppleScript to automate HTML link construction
Authored by: mbroughtn on May 10, '07 12:29:47PM

& the_url
& ""target=_blank>

Please do not break the Back button on my browser. Whether a link on your site opens in a new window or tab should be my choice. Your code takes away my right to choose.



[ Reply to This | # ]
An AppleScript to automate HTML link construction
Authored by: toor on May 10, '07 08:33:14PM

The code is offered as his way of doing things, and as an example.

If you don't like the way it works, change it, or don't use it.

Personally, on my sites, if a link takes the viewer out of my domain then it opens a new window, oherwise, it uses the same window. YMMV.



[ Reply to This | # ]
An AppleScript to automate HTML link construction
Authored by: mbroughtn on May 11, '07 09:30:28AM
The code is offered as his way of doing things, and as an example.
I didn't mean to imply that it was anything else.
If you don't like the way it works, change it, or don't use it.
That was my suggestion/plea/exhortation--don't use that part of the code. It was not my intention to blast the submitter of the hint or the worthiness of the hint. I only quoted the part I felt should be changed, and I explained what that part of the code would do for those who didn't know.

[ Reply to This | # ]
An AppleScript to automate HTML link construction
Authored by: lunarhowl on May 11, '07 08:06:32AM

Does anyone know why this wouldn't work with Eudora? It works just fine for BBEdit, etc., but for some reason in Eudora, nothing happens. TIA.



[ Reply to This | # ]
A different approach...
Authored by: sinjin on May 17, '07 12:15:02PM
A great hint, but a bit of a repeat. :)

See this comment to this hint for an Applescript that will build HTML or vBulletin style links in any text input app/area with a few less clicks. Copy the URL, highlight the link text, run the script and you are done. You can access it via the script menu or mod it to work via the afformentioned launcher applications.

I wrote it to speed-up posting links in forums like these.

[ Reply to This | # ]