World's Simplest Script?

I can do a lot of things with applescript, but I seem to be missing something obvious. I do a lot of linking in web replies and it is just a pain to type out the all the time. I figured I’d finally just assign it to a keystroke…Um, but I couldn’t get it done.

I edit scripts in word all the time to do this sort of thing, and all i want to do is have a global script that would let me press something like Command + Option +Shift +F1 and get a string entered ( possibly with a paste where the [url]is and moving the cursor to the position between the tags to name the link). Writing text to the current application has to be simple, but everywhere I look for solutions everything goes on-and-on about all the other more complicated stuff…

Or is it that it can’t be done?

Thanks for any help!

This should set the markup code to your clipboard…

set the clipboard to "<a href=\"[url]" & {} & "\" target=\"_blank\"></a>"

Tom

Browser: Safari 525.26.12
Operating System: Mac OS X (10.5)

OK, that does help. I came up with this from what you said:

set clipurl to the clipboard
set the clipboard to “<a href="” & clipurl & “" target="_blank">”

That will take the URL I have in the clipboard and add it to the link I’ve copied. Very helpful.

even better:

set clipurl to the clipboard
if clipurl starts with “http” then
set the clipboard to “<a href="” & clipurl & “" target="_blank">”
else
set the clipboard to “<a href="" target="_blank">”
end if

Stops me from entering something that isn’t really a URL

That’s very slick! :wink:
Tom

Browser: Safari 525.26.12
Operating System: Mac OS X (10.5)

Just to complete the process…To get the info into the clipboard with a keystroke took a lot more doing than I’d supposed. Perhaps this will help someone…

I needed to create the script in Automator and save as an application, and thn run it via Butler, which is a free application that allows you to run a script application with a keystroke…

Create the script in Automator:

  1. File>New
  2. Choose Custom
  3. Drag in Run Applescript from Actions
  4. Paste in script

    set clipurl to the clipboard
    if clipurl starts with “http” then
    set the clipboard to “<a href="” & clipurl & “" target="_blank">”
    else
    set the clipboard to “<a href="" target="_blank">”
    end if
  5. Save as application

Install Butler (freeware application)
http://mac.softpedia.com/get/System-Utilities/Butler.shtml

Configure the Shortcut in Butler

  1. Locate butler after install on menubar and choose Customize
  2. Add File with the button at lower left, choose the application stored previously.
  3. Click the Triggers item on the right of the butler screen
  4. Add the hot key by pressing the desired keys

Took far to many hours to figure this out…I can’t believe Apple doesn’t have a way to incorporate something like the quick keys here which had to be done via third party software. But now in my many travels to forums and the like I can create links in discussions by copying the URLs, using 3 keystrokes! (Copy, Refine Clipboard, Paste)

You could add

tell application "System Events"
	keystroke "c" using command down --copy
end tell

to the beginning of your script to save 1 keystroke :slight_smile:

Ian

I assume I could also do:

tell application “System Events”
keystroke “v” using command down --paste
end tell

But I wonder where the focus will be at the time…In any case, this is helpful and gives me more to toy with.

Thanks!