Archive for the 'Macintosh' Category

Improved Dynamic TextExpander Abbreviations

Moments ago I figured out a way to make it easier to use input from a dialog box to add text to a TextExpander snippet. First, I created a AppleScript snippet that requests input from the user:

set currApp to GetCurrentApp()

tell application "textexpanderd" to activate
set userInput to text returned of (display dialog "Input:" default answer "")
tell application currApp to activate
return userInput

on GetCurrentApp()
	tell application "System Events"
		set _app to item 1 of (every process whose frontmost is true)
		return name of _app
	end tell
end GetCurrentApp

Now I can just embed that snippet wherever I need to get user input in a plain text snippet. I used @@textprompt as the abbreviation for the previous snippet, and then created a snippet with the abbreviation #func with the following content:

function %snippet:@@textprompt%() {%|}

Now whenever I need to create a PHP function, I can use that, and it will name the function for me and position the cursor inside the braces so I can continue coding. I’ve used the snippet in other instances to prompt me multiple times for input and build pretty complex expansions.

Cha-ching! I’m loving this. Now if I can write an AppleScript that will think for me …

(Note: I found the code that I’m using to find the currently active application at Daring Fireball.)

Dynamic TextExpander Abbreviations

Ever since I discovered TextExpander a few weeks ago I have been wishing I could get it to dynamically expand abbreviations. What I mean by that is I’d like something like

#func-get_text

to expand to

function get_text() { }

I’ve finally figured out how to do something along those lines using the AppleScript snippet support. The following bit of AppleScript will prompt me for a function name, and then use the result in the snippet:

tell application "textexpanderd" to activate
set funcName to text returned of
	(display dialog "Function Name:" default answer "")
tell application "BBEdit" to activate
return "function " & funcName & "() {%|}"

(Note: The bit above starting with ’set funcName to …’ and ending with ‘… default answer “”)’ should all be on one line; otherwise the script won’t compile.)

If you want to create a TE AppleScript that prompts you for something, the “tell application “textexpanderd” bit will bring the prompt to the front. Then you just have to activate the application you were using again; since I’m always doing my coding in BBEdit, I don’t have to dynamically figure out what app was active.

The nice thing is that TE still sticks my cursor where the “%|” is even though it’s an AppleScript snippet!

Five Happy Observations from Mac Intel/Leopard Land

I’ve now had my new Macbook Pro for a little over a week. This is my first experience with a) an Intel Mac and b) OS X 10.5 (Leopard), so I thought I’d share some things I think really rock with my new setup:

  1. Spaces (OS X’s virtual desktops implementation) - I tried a few third-party virtual desktop programs in the past, but they generally were buggy … and none of them are as slick as Apple’s implementation. I’ve gotten really comfortable with the setup in the last few days.
  2. Time Machine (OS X’s new backup utility) - I plugged in my Western Digital MyBook 500gb drive and it immediately asked if I wanted to use it to back stuff up on. Well, now that you mention it … sure! And, it does this automatically when the drive is set up. I’d like the ability to tell it when not to do backups since a little extra disk usage during the day when I’m chugging away at the drive with other processes isn’t welcome, but other than that it’s slick.
  3. Unity Mode in VMware Fusion - It’s creepy to see a Vista window on my OS X desktop, but it’s much nicer than running the OS in a window. Being able to switch back and forth between OS X and Windows apps rocks. Yeah, I know Parallels does it too, but I’m declaring my allegiance to Fusion since it runs the virtual machines I’ve made in VMware Server and Workstation. That’s just way too valuable.
  4. iCal - Looks much better than it used to look. That is all.
  5. System Preferences - Whoa! They made the network preferences logical! Yeah, I was confused the first time I went looking for Internet Connect to connect to my office VPN, but once I figured out where it was, I was happy. Oh, and the new icon is sexy too!

Now … when I can come up with the spare cash to upgrade to Adobe CS3 in the next month or so, I think all the apps I depend on for most of my work will be Universal Binaries. That reminds me … I have to give some props to Apple for handling the PowerPC => Intel transition so well. Yeah, there were some hiccups with the early machines (which I studiously avoided by being a cheapskate and sticking with my Powerbook for nearly four years) but overall it went really well.

Methinks I Have Spotted an OS X Bug …

Notice anything unusual about the amount of memory Java is supposedly using according to Activity Monitor? Here’s a hint … my disk drive is only 160 gigs …

activity_monitor.png

I *LOVE* VMware Fusion

I’ve looked forward to getting an Intel Mac for some time now, if for no other reason than because I could run a Windows virtual machine significantly faster since there wouldn’t be any need to do “translation” between Intel and PPC instruction sets. Even on my pretty healthy 1.5 GHz Powerbook G4 with 2 GB RAM, XP was glacially slow … and that was after I disabled nearly every non-essential Windows service and ran it at 800×600.

Then VMware introduced their Fusion product, which uses (basically) the same virtual machine format used by VMware Player, Workstation and Server. I’ve got all three products in use at work. I build VPS machines in Workstation, use them in Player, and have a number of Server VPS machines running on host machines at the datacenter. Running Fusion would mean that I could move the VPS machines to my Mac and test them, which would just be cool. Several times in the past, I’ve duplicated a running VPS from the datacenter and tested upgrades … and it’s saved my bacon.

In the last couple of weeks, while I’ve been without my Powerbook after its logic board failure, I created a CentOS5 VPS to use to test things on while I was using the Vista laptop. Yeah, I know I can install XAMPP, but I just don’t trust it for my development work. Of course when I got the Macbook yesterday, I went ahead and installed Fusion on it and copied over the VPS, and had it up and running with a minimal amount of hassle.

And today … just a few minutes ago, I discovered that they have an application that will convert Virtual PC 7 machines to the VMware format. I ran it on my IE7 XP virtual machine, and it worked like a charm. I’ve already ordered a copy of Vista to run as a virtual machine too (just because it’s different enough from XP that I want to be able to test on it without having to use another machine), but I probably won’t get it and be able to set it up until mid-week. Having the XP machine means I can test stuff in IE 7 right now. Yay for VMware!