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 »
5/02/2009
Scenario: You’re working with the Flex SDK and you’re tracing messages to the Terminal via flashlog.txt. The damn logfile has heaps of clutter in it from the last project you were working on, and you want to clean it up.
Solution: Save this snippet and assign it a Quicksilver hotkey:
1 2 3 4
| try
do shell script "rm ~/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt"
do shell script "touch ~/Library/Preferences/Macromedia/Flash\ Player/Logs/flashlog.txt"
end try |
Result: You are happy. Go drink beer.
2/02/2009
A fairly common task in ActionScript projects is to deal with URLs in dynamically loaded text. Whenever I faced this prospect I usually ended up with some half-assed searching for “http://” and then indexOf(” “) to determine when the URL had ended and then smacked a <a href> on either side. Which pretty much meant that “http://___||/**.tasty_cheese_omelete” would be acceptable while “google.com” would not.
Hence I always promised myself that next time I’d write a proper class to deal with URLs so that this bullshit wouldn’t pass anymore.
Regular Expressions have always scared the bejeezus out of me, but I realized there was probably no other option when looking for something that has a valid URL structure. It was surprisingly easy to find some fairly good examples for what I wanted to achieve, and surprisingly difficult to get any of them to work in ActionScript. I’m blaming it on the AS implementation of RegExp, and I’m sure ActionScript is blaming it on my implementation of dumb.
After some swearing though I managed to determine whather a string had the proper structure of a URL but it still wasn’t perfect. I wanted my class to be intelligent enough to accept all valid Top Level Domains (there’s 267 in use) but reject any invalid attempt to pass as a valid TLD. IE: egypt.eg should pass, but breakfast.egg should not. The solution ended up being storing all the TLDs in a Vector and parsing through them to check if the domain was valid.
All in all the class now does a pretty good job, although there are probably still holes in it (let me know about them when you find them).
Check it out and grab it below, and then post a comment explaining to me slowly and carefully that I can achieve this exact functionality with the
1
| String.giveMeAllTheURLs(); |
method or something similar, which I’m sure is what will happen. ;)
The code is freely available here. I would appreciate any credit and that you share whatever improvements you make with me and the rest of the world, but I have neither time nor energy surplus to actually do any enforcing, so knock yourself out.
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/01/2009
I use a 15″ MacBook Pro that I carry between work and home. At work I have a 30″ Cinema Display which means I can actually have half of the Flash IDE showing at once. Mostly it’s plug and play but every once in a while some app just doesn’t realize that I’ve unplugged the huge display and some window ends up at some awkward position where I have to drag it out and resize it, or even worse; It ends up outside the boundaries of the laptop screen altogether.
AppleScript to the rescue. Copy this script and save it into your AppleScripts folder. You can assign it to a Quicksilver hotkey if you’d like, but I find it’s convenient enough to just launch it from Quicksilver in the usual manner.
What it does is simply resizing the window and centering it on the display. There are more elegant ways to do this, but this one works even with apps that have little or no support for AppleScript at all. You can adjust the lines:
1 2
| set position to {220, 50}
set size to {1000, 800} |
to fit your screen real estate as those values are set to center on a 1440 / 900 display.
1 2 3 4 5 6 7 8 9 10
| tell application "System Events"
set frontmostProcess to name of first item of ¬
(processes whose frontmost is true)
tell process frontmostProcess
tell window 1
set position to {100, 0}
set size to {1200, 800}
end tell
end tell
end tell |