News, info, and opinion by Mac users, for Mac users.

July 24, 2008

tips

Use AppleScript to create fake dialog boxes

Posted Jul. 24, ’08, 7:00 AM PT by Dan Pourhadi
Category | Tips

I got a question yesterday in the comments of my Why can’t Apple and China just be friends? post.

Reader Austin wanted to know how I created the “Incompatible Country” dialog box I used as the post graphic:

incCountryfake1.jpg

It’s actually pretty easy: I wrote a small AppleScript in Script Editor (/Applications/AppleScript/Script Editor) to create a custom dialog box with the text I wanted:

display dialog "The country \"China\" cannot be dominated by your products because its population and government are incompatible with your business model." with icon stop with title "Incompatible Country"

The “with stop” code indicates which icon I want to use in the dialog (you can also use “with note” and “with caution”). The “with title” part lets me (obviously) set the title of the box—in this case, “Incompatible Country.”

Using that script, you can create a mock dialog box that says pretty much anything.

And here’s a bonus: If you know how to use SSH to connect to another Mac, you can have fun with whoever’s on that computer by popping up custom dialogs remotely using a shell command like this:

$ sudo osascript -e 'tell app "Finder" to activate' -e 'tell app "Finder" to display dialog "Surfing porn again? Shame on you."'

Enjoy.


2 Comments

Austin said:

Woo hoo! That's awesome, thanks so much. I just expected a reply in the form of another comment, not an actual post. Dan, you rock!

Anonymous said:

Hey, that's great to know. But how did you learn all this Dan?

Leave a comment

 




Visit other IDG sites: