Here is a more complex one that I did with "Caffeinate" (the 10.8 command utility, not the "Caffeine" app from Lighthead).
The individual files are available at https://github.com/s...inate-workflow/, just wander through the folders.
Better explanations below.
Caffeinate v Caffeine
Pros: Caffeinate is already on Mountain Lion. With this workflow, you can operate it through just the keyboard.
Cons: No visual status check to see if it's running. Only on 10.8.
Pros: Visual status (see coffee cup on menubar). Normally you have to use the mouse to activate (although toggles exist here). Available on more than just 10.8
Cons: Yet another app to install (although it is free). Yet more clutter in the menubar.
What I did
The scripts are written in php, and I set it up so that caffeinate takes these commands:
* status — Shows whether caffeinate is active and returns the number of minutes if it is.
* en — Enables caffeinate.
* en "minutes" — Enables caffeinate for X minutes.
* dis — Disables caffeinate.
I divided it into three different php scripts.
The first one takes the commands "help" or "Help" and also takes any command that isn't recognized. Then, the help display (which are the commands above) are displayed via Large Text.
The second one is a status check that executes a few shell commands to see if caffeinate is active (using ps -ef and a regex), and, if it is, then it also pulls the command that launched caffeinate so that I can find whether or not there was an expiration time or if it was enabled indefinitely.
The third one enables and disables the utility via the command line (again). Apparently, you can launch the process several times, and so I used a killall command to take them out on disabling them. If enabling, it checks to see if the utility is already running, if so, then it doesn't launch it again but reports that it is already running.
Also, the status script and the en/dis script use the notification center to report back instead of Large Text.
So, these scripts were thrown together quickly, but they might also be good for others to look at if they need some guidance working with php scripts or other arguments as I also tried to comment them a bit. They also show how to use system commands (especially backgrounding the caffeinate command) via php, which, of course, isn't always the best idea. And these scripts could also be written better, so keep that in mind.
I'll say that I didn't like the Large Text to display the help function because I can't control the formatting well, but it seemed like the best option. The notification center cut off the text too quickly. Is there another way to display a quick help via Alfred when a command goes wrong?