Using AppleScript to Automate Data Entry

I was working on an app today and ran into a problem: I had to transfer data from a table in a Microsoft Word document to a dictionary in a dictionary in a dictionary in a property list in Xcode. After copying and pasting several times—I had 243 total entries to copy—I figured there had to be a better way. So, I fired up AppleScript Editor and wrote this quick script to do nine at a time:

repeat 9 times
	tell application "Xcode"
		activate
	end tell
	
	tell application "System Events"
		keystroke tab
		keystroke tab
	end tell
	
	tell application "Pages"
		activate
	end tell
	
	tell application "System Events"
		keystroke "c" using {command down}
		delay 0.5
		keystroke tab
	end tell
	
	tell application "Xcode"
		activate
	end tell
	
	tell application "System Events"
		keystroke "v" using {command down}
	end tell
end repeat

Nothing fancy, but it worked, and I was saved from carpal tunnel syndrome. So if you find yourself needing to do something tedious, repetitive, and (most of all) easily reproduced, you too can turn to AppleScript to get it done. I won’t spend too much time on explaining the code, but just know that you have to enable access for assistive devices in System Preferences before doing it.

Selling “Physical Goods” or “Goods and Services Used Outside of the Application” in an iOS app

Since this question has come up a few times, I thought I’d record my answer to a common question:

Can I use an iPhone app to sell something outside of the App Store?

Reading Apple’s rules for the App Store makes developers nervous. We’re walking on eggshells, hoping that our application will not run afoul of the myriad of regulations put forth by Apple for inclusion into the store. So, questions like this come up. I’ll reproduce my answer here:

Obviously, I am not a lawyer, but I think you’ll be OK. Here’s my interpretation of the three relevant rules from the developer guidelines (emphasis mine):

11.1 Apps that unlock or enable additional features or functionality with mechanisms other than the App Store will be rejected.

11.2 Apps utilizing a system other than the In App Purchase API (IAP) to purchase content, functionality, or services in an app will be rejected.

11.3 Apps using IAP to purchase physical goods or goods and services used outside of the application will be rejected.

The first rule prohibits you from unlocking anything inside of your app with something other than the App Store. This would prevent you from, say, making a game that downloads new levels from your server based on your membership to a website.

The second rule prohibits you from, say, making a game and enabling PayPal in it to unlock more levels. Apple wants you to use in-app purchase for that.

The third rule—and this is where it gets interesting—prohibits you from using in-app purchase in an application to buy “physical goods” or “goods and services used outside of the application.” Nowhere does it say, however, that you can’t use other purchasing systems.

With that third rule, I think what Apple is saying is this: anything that runs on the iPhone must be purchased through the App Store, and everything purchased in the App Store must run on iOS. For something like insurance, which isn’t new functionality in the app, I think you’ll be OK. This is absolutely worth an e-mail to Apple’s technical support staff, but if you look at Amazon’s app, you can purchase physical goods using Amazon’s checkout system.

I’d love to be proven right or wrong on this. If my reading is correct, then using an iOS app as a storefront is perfectly acceptable. If I’m reading this too charitably, then you’re better off making this type of application for a different platform.

Autorelease is Not Your Friend

How many times have you written this line?

NSMutableArray *foo = [[[NSMutableArray alloc] init] autorelease];

At first glance, it looks fine. foo is an autoreleased NSMutableArray that you can use and, at the end of the method, it’s gone into the ether of the autorelease pool. Don’t get me wrong, most of the time, this use of -autorelease is acceptable. But, in this post, I’ll try to convince you to use autorelease differently in subtle ways. Continue reading Autorelease is Not Your Friend

Apple Doesn’t Like “Die, You Gravy-Sucking Pig-Dog!”

There’s a relatively well-known Easter egg in BSD’s shutdown.c: a function named die_you_gravy_sucking_pig_dog. It turns out that Apple doesn’t care to have such uncouth function names floating around, so they re-defined it:

#ifdef __APPLE__
void log_and_exec_reboot_or_halt(void);
#else
void die_you_gravy_sucking_pig_dog(void);
#endif

Sure, it does the same thing, but I don’t think log_and_exec_reboot_or_halt has the same panache.