Archive of articles classified as' "Automation"

Back home

Clean flashlog.txt with a keystroke

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.

No Comments

Open Safari URL in Firefox

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.

No Comments

Center and resize window with AppleScript

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
No Comments

Quicksilver actions the easy way

9/12/2008

Quicksilver Icon
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.1

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 2, 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

1
on open these_items

refers to the current selection in the first pane, and after that you can use the variable

1
these_items

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!

  1. A consideration I’m not really used to having the foresight of taking.
  2. Settle down AppleScript developers. I said ‘get started with’.
No Comments

Better (AS3) imports in TextMate

1/12/2008
Summary: In which Martin has concocted a hack to make importing packages in TextMate a wee bit easier.

TextMate TextMate TextMate. I might as well make this a pure TextMate blog soon, but I can’t help it. My love for this app is overwhelming.

I spend a lot of my time writing ActionScript, and one thing I’ve always envied users of Flex Builder (Which I avoid if I can) and FlashDevelop (which isn’t available on the Mac) is the auto-importing of classes, I.E. when you type

1
var s:Sprite;

the IDE checks whether that class is already imported, and if not imports it.

Now, what I’ve managed to do still isn’t even close to that functionality and let me say right away that the meat of this trick is the excellent work by the creator of the ActionScript 3 bundle for TextMate; Simon Gregory et al.

Simon has in his bundle included a ‘Auto complete imports’ command which searches both the packages in your project and the packages included from Adobe (flash.*) which makes it easy to get completion for any class you’d want to import.

Like so:

  • You want to import the
    1
    flash.net.URLLoaderDataFormat;

    class, which is a long-ass line to type out.

  • Instead you type ‘URL’ and trigger the auto-complete command. You’ll get a drop-down with all classes starting with “URL” and then choose the proper one.
  • 1
    import flash.net.URLLoaderDataFormat;

    is typed out for you. Yay!

However, now you have to copy that text, move on up to your import statements, paste it and then find your way back to where you were.

Boy do I wish I knew Ruby well enough to actually just augment that command to make it obey my wishes, but alas; My ruby-Fu is weak and so I turned to the weapon of the feeble TextMate hacker; Macros.

Basically the workflow now is:

  • Perform the steps as mentioned above to get the completion for your import. However; This time the output would be
    1
    import flash.net.URLLoaderDataFormat; move

    . The ‘move’ at the end there will work as a tab trigger for the macro, so the next step is to press tab, and then (hopefully) the import statement is moved up to it’s brethren, and you end up back where you were. Here’s how it works.

  • When you press tab you trigger the macro which will perform the following steps:
  • Select the line with the import and cut it.
  • Enter the word ‘asdf’ in place of the import statement.
  • Search for the last occurrence of the word ‘import’ in the document.
  • Move to the line below said last import.
  • Paste the import statement from the clipboard and indent it properly.
  • Search for ‘asdf’ in the document and delete it, leaving the caret at the position it was when you launched the macro.

Like I said; It’s more of a hack than anything else and if someone comes up with a proper solution please let me know. The main weaknesses here are:

  • You can’t just hit the combo in the process of typing out a statement. If you trigger the auto completion at the word ‘Sprite’ in
    1
    var s:Sprite = new Sprite();

    The line

    1
    import flash.display.Sprite;

    will end up in the middle of the statement. Likewise if you trigger the combo on the same line as any other code, that code will end up with the imports. The command must be triggered on a line of it’s own.

  • Dependencies: If you want to change the tab trigger to something else than ‘move’ you’ll have to change the output from the auto-complete as well.
  • Not really all that elegant. Having to do two actions (even though one is just pressing tab) seems a hassle.

With all that out of the way: Grab it if you want it!
Zip here.
Please note: I didn’t really want to distribute a modified version of Simons work, so if you want to output the ‘move’ keyword for the tab trigger you need to go into the ‘Auto Complete Imports’ command of the ActionScript 3 bundle in the Bundle Editor and make a miniscule edit at the bottom of the code.

1
2
3
4
5
6
7
8
#Change
else
  print "import " + choice + ";"
end
#to
else
  print "import " + choice + "; move"
end

That’s all folks.

2 Comments