Run UNIX commands in an AppleScript

Mac Tips No Comments

Leopard Logo If you want to easily encapsulate a shell script or a UNIX command in an AppleScript, but that command must be executed as root (through a sudo), just do the following (all one line):

do shell script "unix_command" password "your_password" with administrator privileges

where unix_command is the actual command you want to execute. In my case, this was to set the Sharing hostname to match the actual DNS hostname of the computer, which looked like this:

do shell script "sudo scutil --set ComputerName `hostname`" password "NoWayJose" with administrator privileges

By the way, if you do intend to set the Sharing name to the computer’s hostname, make sure to include the backticks (located under the ~ sign at the top left of most keyboards) around the word hostname, otherwise you’ll just name your computer ‘hostname’ rather than its DNS name.

It’s important to note that this a) leaves your password in the script, and b) runs silently. If you just want to be prompted for a password, add the following lines before and after your script, like this:

tell application "Terminal"
do script "sudo scutil --set ComputerName `hostname`"
end tell

This will launch Terminal, which will then prompt you for your password in order to sudo.


Don’t hate Windows ‘cuz it’s popular, it can still show boobies good

Musings No Comments

You know what? I’ve had enough of the self-righteous bullshit I constantly hear from people who, for one reason or another, use obscure operating systems and feel it necessary, solely for that reason, to rag on Windows at every opportunity. Take for example, the plethora of smug, overbearing Mac users that seems to crawl out of the woodwork to make fun of virus protection. Case in point is a poll on Techdirt.com, which asks users to list the number of ‘anti-’ programs running on their desktop. Clearly, this was intended for the 95% of users out there running Windows, but that didn’t stop the beret-wearing crowd from chiming in brilliantly:

Why is it that if somebody doesn’t have ANY anti-something, that they are “living dangerously”?

Perhaps it should be renamed to “I don’t use an OS/Software the forces me to use this junk”

Here’s the thing: I love Macs. I think Linux is neat. But the fact of the matter is that most of the world is running Windows, so most of the pond-scum writing viruses and spyware are going to target it, because they’re skeevy assholes, not complete idiots. No one really cares if their popup displays on Safari 1.0, if their malware-anti-spyware product will install on FreeBSD, or if they can hijack your browser to dial aged Portuguese women in South Jersey for per-minute tele-sexual services. There’s millions of other people out there running Windows who are ready to eat that shit up. But you know what? If your operating system was popular, all the other kids would hate it too, and try to hurt it both phyisically and psychologically. Plus, here’s the thing that other OS users are always afraid to admit. Windows users can afford to run anti-spyware, anti-virus, anti-spam, anti-phishing, anti-bellum, and anti-quated software all at the same time on their machines, and still be able to do exactly what they want with their computers. And you know why? ‘Cuz all that porno’s optimized to run on fuckin’ IE, bitch. So have a nice day staring at the command line, nerd.