kdmurray.blog

The crossroads of life and tech

Running Shell Scripts from the Finder in OS X

Bad AppleOne of the things that drives me insane about the Mac on occasion is the ability of OS X to make some of the simplest “power-user” tasks very difficult. Case in point – the ability to execute a shell script from a finder window (or by extension, the desktop).

In most sane operating systems, including Linux and Windows, if you double-click on an executable file, it executes. It’s just that simple. If you create a batch file on Windows (anything ending in .bat or .cmd), the operating system treats that file type as executable and will try to run the contents as command-line commands. In Linux, an operating system which is similar under the hood to OS X, you need to set the “executable” bit in the permissions. This is certainly more of a super-user type task than simply renaming the file, but still quite simple — and consistent across the POSIX world… except for Apple.

chmod +x myscript.sh

So the question is, how do I do this on my Mac? The answer I’ve been given by several people until today was that you would need to use AppleScript or Automator (or Xcode) to create a program that could be run from the Mac GUI. As ludicrous as it seemed, Apple’s tendency to force users to do things the “Apple way” made that quite believable. However I found a post today on Adam Young’s blog from back in 2008 which showed that it is, in fact, possible to do this — it’s just a bit harder than on any other OS. Essentially you have to do both the Linux (chmod) step, and the Windows (specific file extension) step.

mv myscript.sh myscript.command chmod +x myscript.command

You need to use the .command extension for the Finder to actually attempt to run your shell script. An identical file with the execute bit set but with a .sh extension will simply open up in Xcode (or whatever editor you have set for .sh files).

Podcast Roundup – New (to me) Apple & Mac Podcasts

podcast_subscribeI was on the hunt for some new Mac and Apple podcasts after becoming frustrated with the amount of blatant fanboyism and un-necessary Microsoft and Windows bashing I was hearing on the shows I had subscribed to. I wanted more shows that take an even-handed approach like Mac OS Ken or a lighthearted approach like the Nosillacast. I put a call out on Twitter and Google plus for recommendations and was given a couple of great new (to me) shows to listen to.

Mac Power Users

This show is absolutely brilliant. I’ve only been subscribed for the past week or so, but I’ve gone back and reviewed the last 10 episodes.

Katie and David do a great job of covering topics in enough detail to provide a complete review without getting into too many inanities. There are typically two types of shows. The topic-shows provide a deep-dive on a specific topic filled with lots of tips, tricks and keyboard shortcuts. The other show type is a “workflow” show where they typically bring on a guest to talk about how they use Mac and iOS products to get their work done productively.

Typical Mac User

I listened to the Typical Mac User a number of years ago, shortly after

Victor started the podcast I suspect, and for whatever reason drifted away from it. When George Starcher suggested over G+ that I check it out again, I found that I really enjoyed it. I’ve listened to a few different episodes in the past week which ranged from uber-beginner intros to OS X Lion, through to highly-involved automator/applescript discussions The show provides a good balance of introductory, mid-range and technical discussion and offer a range of guests to get insights on different parts of the Mac community.

Guest Spot – Knightcast 0056 “The Best of KWTV Live”

I recently had the honour of being asked to be a guest on Knightwise’s podcast during his KWTV Live event in September. He took the opportunity to interview three different people about the current state of the three major operating systems, Linux, OS X and Windows. The three guests for the evening were:

Larry spoke on the state of Linux and what drives Linux adoption; Bart covered the highlights and lowlights of OS X Lion in some detail; and I talked about the Windows 8 developer preview and the state of Windows tablet PCs.

Give it a listen!

Creating ISO Images from the OSX Command Line

A super fast way to create ISO images (or any kind of bit for bit copies) from the OS X (or linux, or unix) command line is to use the DD command. This isn’t without it’s risks since the DD command will duplicate byte for byte all data from one location to another, but once you’ve found the necessary information you can easily replicate data.

I needed to create a copy of my Windows XP installation CD to use for setting up new virtual machines. Since it’s quicker to install VMs from an ISO image rather than from the installation media I wanted an ISO of my CD. The built in OS X disk utility can make this work… in theory. My copy of disk utility (on Snow Leopard) didn’t want to recognize the CD. So I turned to my command line knowledge.

I should also note that before you can read the CD using DD, you will need to unmount it:

sudo umount /dev/disk1s0

You’ll be prompted for your administrator password, then you’re in business.

To create an image of a CD (or DVD or anything else…) use the following:

dd if=/dev/disk1s0 of=/Users/kdmurray/Desktop/WindowsXP.iso bs=64k

  • if= input file, in this case our Windows XP CD
  • of= output file, the actual ISO file you want created
  • bs= block size, the size of chunks the tool will work with

I did a few speed tests at 16k, 32k, 64k, 128k, 256k and 1M and found that the 64k seemed to be the ideal block size on my machine. This will vary by CPU, and possibly by hard drive controller, so do a few contolled tests first. To do a test, start the copy process, then stop it after 20-30s (ctrl-c). Whichever one copied the most in 30s is the one you should use.

That’s all she wrote, folks. Happy command-lining. :)

Security on the Mac

Recently I came across a discussion on a Mac forum with some people discussing how shocking it was that Apple had been recommending that its Macintosh customers consider using anti-virus software.  This is a discussion that has always raised my ire, as the supposed superior security of the Mac has always been an issue of numbers.

No operating system is perfect, they’re all designed by people and are full of flaws as a result.  It’s important to keep in mind that one of the reasons that Mac OS X has had precious few problems with viruses and other nasties is market share.

Writing viruses is much like sending out mailers for advertising your new business. The more people you reach with your message (or malware) the more people you’ll connect with (infect).

If you want to infect lots of people, you write your malware for Windows.

Five years ago the market share of the Mac was in around the 5% mark, meaning that if you wrote a virus for the mac and distributed it to 20 million computer users you’d infect 100 people (at a rate of 1 in 10,000). If you write for Windows and infect people at the same rate, you’ll infect 1900 people.

With the market share of the Mac increasing, so does the surface area for attacks. Many Mac owners have become complacent over the years believing that they are safe because they use a Mac. As a result the infection rates of Mac systems could be much higher than Windows-based PCs if malware authors decide to target the Mac platform.

Food for thought.