A few random AppleScript snippets

14/01/2010

I was just writing an AppleScript to look up words on the excellent NinjaWords and decided to post it in case someone else needs something similar. Since one snippet of AppleScript is not a very meaty post, I’ll throw in a couple extra.

Look up word on NinjaWords

Select a word and copy it to the clipboard. Then invoke this script via Quicksilver or LaunchBar or whatever is your favorite tool for invocations.

1
2
3
4
set clip_url to (the clipboard as string)
set lc_url to do shell script "echo " & clip_url & " | tr '[:upper:]' '[:lower:]'"
set ninjaURL to "http://ninjawords.com/" & lc_url
do shell script "open " & ninjaURL

Wrap link in ‘a href…’

Note: This one will look slightly different depending on whether you are using Quicksilver, LaunchBar, whatever. The key is that you pass a string value into the script and it returns one back to you. This example is for LaunchBar.
Copy a link to the clipboard, invoke the script, paste your now a-tagged link.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
on handle_string(vanillaStr)
  set quote to ASCII character 34
 
 
  set openTag to "<a href=" & quote
  set closeTag to quote & ">"
  set finishTag to "</a>"
 
  set TempTID to AppleScript's text item delimiters
  set AppleScript's text item delimiters to space & ":" & space
  if (count of text items of vanillaStr) is greater than 1 then
    set urlStr to text item 1 of vanillaStr
    set linkStr to text item 2 of vanillaStr
    set returnStr to openTag & urlStr & closeTag & linkStr & finishTag
  else if (count of text items of vanillaStr) is 1 then
    set urlStr to text item 1 of vanillaStr
    set linkStr to "linkage"
    set returnStr to openTag & urlStr & closeTag & linkStr & finishTag
  else
    beep
    return
  end if
  set AppleScript's text item delimiters to ""
  tell application "LaunchBar"
    perform action "Copy and Paste" with string returnStr
  end tell
end handle_string

New File

Sometimes you just want a dang text file to magically appear.

1
2
3
4
5
6
7
8
9
10
11
12
try
  tell application "Finder" to set the this_folder ¬
    to (folder of the front window) as alias
on error -- no open folder windows
  set the this_folder to path to desktop folder as alias
end try
tell me to activate
set thefilename to text returned of (display dialog ¬
  "Create file named:" default answer "filename.txt")
set thefullpath to POSIX path of this_folder & thefilename
do shell script "touch \"" & thefullpath & "\""
do shell script "mate \"" & thefullpath & "\""

That’s it for now. I have some gems saved for a later post, but they wouldn’t make sense out of context so you’ll just have to wait.

2 Comments

Set up your own lifestream using FriendFeed and… Dirty hacks

10/01/2010

Lifestream
When Iceland went bust and started selling .is domains I grabbed martin.is. Of course I did. That’s the kind of guy I am. Even as I swiped that credit card (and by “swipe” I mean “typed in all my info into the appropriate boxes.”) I knew I had no idea what I was going to use it for, but what the hey; I’ve done plenty of even stupider domain purchases that never led to anything1.

So finally, the other day I decided to set up a “lifestream”. An aggregate feed of all the highly interesting stuff I do on the web. Not because I think anyone particularly needs or wants to know. It just seemed like the kind of thing that goes on a domain called “martin is”.
I really didn’t want to spend loads of time on this. I have a job, a daughter and a blog that are all already wailing for my attention, so tried plugging all my stuffs into a WordPress install using FeedWordPress and a couple of other similar plugins, but I found the results to be (unreliable | explosive | bewildering)2.

Alrighty then. What services do I know of that aggregate information like this? FriendFeed! I headed over to FF, and sure enough; Within half a minute I had managed to plug all the crap I generate into one massive hunka’data. In addition to supporting a bunch of services Friendfeed actually does pretty well parsing feeds from other sources and cutting the entries into little blurbs. Now only to get it out of there and onto my domain.

Read the rest of this article »

  1. Seriously. Need a domain?
  2. Pick one.
No Comments

New blog!

3/12/2009

No no. I’m not about to start a kerfuffle about changing the location and / or name of my blog again. I just wanted to make sure you’ve heard about the new ria.creuna.com site.

Basically me and the other RIA-developers broke out and started our own blog. If you like the code, geek and tech content from this site you should be sure to check it out. For example you could start with my huge post about URL Recognition, or you could read how my co-worker exposes the clickTAG sham for the lousy stinky piece of bad stuff it is.

No Comments

Capture key sequences in ActionScript 3. AKA The Konami Comeback.

6/06/2009

Contra Konami
Lately the internet has had a wave of sites using the cherished Konami Cheatcode to reveal easter eggs or similar functionality in the site or app.

I wrote a (crappy but working) class to implement such functionality in ActionScript about a year ago here.

I decided to polish it up a bit for the benefit of myself and anyone else and in the process ended up creating a small utility class to work with keystrokes in the process.

You can download the (fairly self-expaining) classes and a sample project right here, or read on for a bit of explanations.

(Text) Keys.as.
(Text) Konami.as.
(Archive) Neatly zipped + example.

Read the rest of this article »

3 Comments