There are a few tasks I tend to do repeat every now and again and they can be a bit annoying to do. So I tried to write little AppleScripts for them.
These scripts used to reside in Apple's script menu for instant access from every application. But I didn't find said menu well executed after a while. Most notably, sometimes it took ages to open and was a pain to use with the mouse. And my attempts to assign keyboard equivalents to my scripts in the menu via the keyboard system preference yielded unreliable results at best. Plus, there were other annoyances – like the fact that applications like Mail or iTunes have separate script menus of their own. Seems like doing proper integration and a consistent UI was too much for Apple once more. File under: shiny but not very useful.
In come those pretty new launcher applications. They will happily give me easy access to and execute any AppleScript I throw at them (although the new LaunchBar beta doesn't seem to hide itself afterwards). That's nice and means I actually use these scripts a lot more these days because I don't have to struggle with the script menu to access them.
Two handy blogging related scripts are the following.
Safari to HTML Link grabs the current URL from Safari (insert rant about Safari's limited scriptability here) and generates an opening anchor tag for that URL with the title of the page (piped through UnicodeChecker of course to have clean HTML) in the
title attribute and then puts it on the clipboard. It's simple but efficient:
tell application "Safari" set d to document 1 set myURL to URL of d set myTitle to name of d end tell tell application "UnicodeChecker" set myURL to escaped representation of myURL set myTitle to XHTML representation of myTitle end tell set myLink to "<a href=\"" & myURL ¬ & "\" title=\"" & myTitle & "\">" set the clipboard to myLinkDisclaimer: this works well for me. It may not be the holy grail of such scripts. (I.e. I am not quite sure whether it is correct to escape a # in URLs when it marks an anchor).
The other script helps me to insert images. Usually I crop the images in GraphicConverter and use its nice save features. And while the image is still opened in there, I have a script to generate the appropriate
img tag, including the image's size, the file' likely URL and, of course, an empty
tell application "GraphicConverter" tell window 1 set Dimensionen to image dimension set Dateiname to name end tell set Breite to item 1 of Dimensionen set Hoehe to item 2 of Dimensionen set myTag to "<img src=\"graphics/"&¬ Dateiname & ¬ "\"style=\"width:"&Breite &"px;height:"&Hoehe & ¬ "px;\"alt=\"\">"; set the clipboard to myTag end tellAgain, this fits mainly my own needs. It might be more general if it tried to properly escape 'fancy' file names, say. But I have had too much trouble with non-ASCII stuff being broken when being transferred to or residing on non-Mac systems that I am not going to use those myself.
If you find yourself doing similar things frequently, help yourself to these scripts. They are little and may save some time. These little things are what scripting can be really nice for.
Received data seems to be invalid. The wanted file does probably not exist or the guys at last.fm changed something.