Hard and Pipelinks with Applescript!

What this is good for

When you go through a bunch of text that you have already written, putting in hardlinks is boring. That is why I wrote an AppleScript script to help you out! The first script takes the text you have selected and places brackets around them - the second one does the same, but offers you the possibility to make a pipe link instead :-)

How to use the scripts

These scripts assume that you use BBEdit 6.1 for OS X. If you don't, just replace the relevant line with whatever program you use. Copy and paste the script to a new Applescript, replace the program, and you are set!

If you don't know what to enter as your program, just record a new script and do an action (copy something, for example) in the program you use. That way, the tell application part will be filled in by AppleScript.

To use the script, select what you want linked, and then run the script! If you bind the script to a function button, you can make hardlinks by just pressing F7 (for example)! Saves lots of time and typing - especially if you (like me) use a Norwegian keyboards, where the brackets can only be found through excessive finger acrobatics. You can also use the Script Runner that comes with OS X, if you prefer.

Hardlinks:

tell application "BBEdit 6.1 for OS X "
    activate

    set e2clip to "[" & selection & "]" as string
    set the clipboard to e2clip
    paste

end tell

Pipelinks:

tell application "BBEdit 6.1 for OS X "
    activate

    display dialog "What would you like your link to point to?" default answer "" & selection
    set e2pipelink to text returned of the result

    set e2clip to "[" & e2pipelink & "|" & selection & "]"
    set the clipboard to e2clip
    paste

end tell