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.
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.
17/01/2009
Scenario: You are browsing in Safari (because it’s speedier than Firefox) and feel the urge to inspect the site in Firebug or the Web Dev Toolbar.
Solution: Save this script and activate it from QuickSilver.
1 2 3 4 5 6 7 8 9 10
| tell application "Safari"
activate
set theUrl to the URL in document 1
end tell
tell application "Firefox"
activate
OpenURL theUrl
end tell |
Result: You are happy. Have a coffee.
9/12/2008

Just encountered bliss deep down in the Quicksilver Google Groups forum. I was trying to save myself a keystroke as usual. More specifically; I often open folders and files in TextMate, and the steps for doing so with Quicksilver are
- 1: Type the first few letters of the folder/file.
- 2: Tab over to the next pane and type “wi” to bring up “Open with” instead of “Open”.
- 3: Tab over to once more and type “te” to bring up TextMate.
- 4: Hit return.
Which is, I suppose, not too bad. However I wanted the flow to be more like this:
- 1: Find the folder/file
- 2: Type in “wi” to bring up a custom action to open the file in TextMate.
- 3: Hit return.
No, it’s not a major step but every single keystroke matters. And besides; This specific action isn’t really the point here.
The point is that to my amazement there wasn’t any simple way to assign a abbreviation to this type of action. That is; an action that needs input in more than one pane. Being a stubborn bastard I started sniffing around on how I could create my own Quicksilver plugin to perform this seemingly simple task. It seemed however that to create a Quicksilver plugin the way to go was Objective-C which I don’t know (the books are shipping from Amazon as we speak). I sat down to make a go at it in XCode, but I just had to give up before I broke something.
Then; Severely undocumented for such a wonderful feature, it turns out that Quicksilver commands can be written in AppleScript. I don’t mean the fact that you can run AppleScripts from Quicksilver, although that’s nice as well. You can actually create commands that’ll behave just like the native commands in Quicksilver, such as “Reveal”, “Copy to…” or “Go to path in Terminal”. With AppleScript being a ridiculously easy language to get started with , this is huge news.
It means that instead of getting to grips with the intimidating world of XCode, my problem could be solved in four human-readable lines:
1 2 3 4
| on open these_items
tell application "TextMate" to open these_items
tell application "TextMate" to activate
end open |
The trick is in the opening line
refers to the current selection in the first pane, and after that you can use the variable
to manipulate with AppleScript all you want. When you’re happy with your script, copy it to ~/Library/Application Support/Quicksilver/Actions and restart Quicksilver. You might also want to go into the Quicksilver preferences and give it a higher priority, or alternatively assign it to an abbreviation.
Have fun!