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.
10/01/2010

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 anything.
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).
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 »
14/12/2009
I noticed that my little app for migrating your data from Things to The Hit List still gets some hits. I haven’t really looked at it for ages, but I wasn’t terribly surprised to see that it’s broken under Snow Leopard.
I decided to fix it, expecting AppleScript projects in Xcode to work pretty much the same that they did before, and brother was I mistaken.
It seems that Apple decided AppleScript as a simple to grasp scripting language really has no place in Xcode anymore, and Cocoafied the bejeezus out of it. On the surface using the new Cocoa / AppleScript bridge feels like playing a nazi in most hollywood war movies. You’re still speaking English (Cocoa), just with a horrible German (AppleScript) accent.
The Migrator is just a little quick and dirty utility app, which AppleScript is perfect for, but rewriting this for 10.6 I felt I might as well have ported it to Cocoa (since I’m in the process of learning Objective C anyway). I didn’t though. I hacked my way through it using the Bridge, and I felt like Xcode was berating me the whole time.
I’m excited about Cocoa and Objective-C, but I loved AppleScript for what it was. I’m still going to be using AppleScript a lot, but unless I “See the light” of the Cocoa Bridge, I don’t think I’ll be making any GUI apps with it anymore. I also find it telling that there seems to be no documentation for the Cocoa / AppleScript Bridge except for the release notes that I can find.
Rant over.
Disclaimer:
- This works fine for me. I make no guarantees that it’ll work for you. I think it will, and I’ll try to help you out if it doesn’t, but I’m not liable if your Mac explodes.
- Caution: If you check the “Delete items from Things” option your items will be deleted from Things.
- In order for this to work the app will empty your Things trash can regardless. If you really need the stuff in the Things trash can, perhaps it shouldn’t be in the trash.
- I don’t have a Leopard machine handy, so I haven’t tested the Leopard version since I first posted it in May. It worked then, so it should work now.
Github
App – Leopard
Source Code – Leopard
App – Snow Leopard
Source Code – Snow Leopard
14/05/2009
Edit: I updated the app to work on Snow Leopard. Go here to get the app or source code.
So this all started out with me pining for the release of the fabled iPhone version of The Hit List. I started out just wanting to create a script that would let me use Things Touch to gather tasks when I was out and about and then transfer them to The Hit List and delete them from things. Seeing how I already had a license for Things this seemed to be my best option for the time being. (Sorry Appigo Todo. It’s not you, it’s me.)
So this is all just exposition, because:
1. It’s too klugey a way of going about this to actually be useful
And 2. it’s easier to achieve almost as good a result by just syncing through iCal.
So now I’m sitting here with a heap of useless code and decided to see if I could repurpose it to do some good.
I present to you the Things Migrator. This is a small app that does one thing only. It grabs all of your to-dos from Things and migrates them over to The Hit List.
Now, not all of the same metaphors apply in The Hit List as they do in Things, so some of the data will inevitably be lost or confuddled. Below is a short summary of how the migrator will treat the different kinds of data.
Tags are transformed into /Tags or /Multi word tags/, Projects become Lists and you can map Areas into /Tags, /Area name tags/ or @contexts.
Issues that may or may not be improved upon:
- It’ll only migrate open tasks and it’ll ignore Things’ “activation date”, “creation date”, and pretty much anything to do with “per sons”.
- Links to local files will not be read. I can’t figure out how to decode the stupid HEX-string I get into a proper path. Instead the script will insert a note alerting you to the fact that somehting’s missing.
- URL links will for now show up as the full HTML link, i.e. <a href="http://ctrloptcmd.com">my link</a>. I’m sure it’s easily fixable, but it’ll have to wait until I know if anyone at all wants it seeing how this string parsing in AppleScript is getting on my balls.
- It is, as mentioned before, a one way street. There’s no syncing back to Things from THL per now, and I don’t know if there ever will.
Please note that this is experimental stuff and I take no responsibility for crap that may happen!
That said, it seems to work pretty well and you can download the application (with a nice GUI) or the full XCode project here.
Comments and feedback is always appreciated.
6/03/2009
How’s that for a TitleCased title?
So I’ve been checking out Path Finder again. The thing with Path Finder is that it’s very nearly awesome, but there are a few things that bug the hell out of me. I may or may not come back to the most irritating shortcomings in a later post, but I’m going to address one of the main issues straight away; Path Finder has crappy support for AppleScript.
I love that little quirky language that actually gives me loads of control over the OS, but for some reason you can’t just rewrite your old AppleScripts to do a check for the current “Finder app” and react upon it with the same code. I have no idea why porting the Finder Dictionary to the Path Finder Dictionary is so hard (if I did I’d be writing some way cooler code than I currently am) but it bugs the hell out of me when some of my most frequently used scripts won’t work anymore. It’s like sitting down on a Mac that hasn’t got Quicksilver installed. You feel like you’re typing with boxing gloves.
Therefore I’ve set out to port my most crucial scripts so they’ll work whether I’m in Finder or Path Finder.
Read the rest of this article »