Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

madog

macrumors 65816
Original poster
Nov 25, 2004
1,273
1
Korova Milkbar
I was just reminiscing over OS 9 and remembered about the Shutdown Items that you could run [scripts and such] upon [obviously] shutdown of the computer. Is there an equivalent to that in OS X? It might be something like a cron script [which I'm not all that familiar with] but I'm guessing it won't be as easy as creating a folder inside the System Folder [or System/Library].

Any help would be great, I've been searching here and in google and have found the question, but not the answer [the simpler the better!]. TIA
 
It might be something like a cron script [which I'm not all that familiar with] but I'm guessing it won't be as easy as creating a folder inside the System Folder [or System/Library].

You're on the right track and it is (almost) that easy. Startup items also double as shutdown items. You can create a startup item that doesn't do anything at startup and does whatever it is you want at shutdown time.

Details here.
 
You're on the right track and it is (almost) that easy. Startup items also double as shutdown items. You can create a startup item that doesn't do anything at startup and does whatever it is you want at shutdown time.

Details here.

I actually found that link in my google searches and my problem was that I actually don't know what to do with it. More specifically, I don't know what to insert in the stopservice section of the script. Like how to run an applescript reminding my father to shut off the printer for example. It's just that I'm not all that familiar with unix [other than: ls and rm -R]. It's probably something simple like, "# open users/me/documents/reminderscript". This is turning into a scripting thread now [sorry mods] but here is the post from the link if anyone can help me with it. [Hold my hand, please!]

I found a clean way to run programs at shutdown: simply register whatever command you want to execute as a service. A service has a Start and Stop functions. Stop function is executed upon shutdown.

To make your own service: create a directory in /System/Library/StartupItems/ or /Library/StartupItems/; place a file of the same name as the directory there with the following contents:

Code:
#!/bin/sh

. /etc/rc.common

StartService ()
        {
         # what to do on boot (can be empty)
        }

StopService ()
        {
         # what to do on shutdown (can be empty)
        }

RunService "$1"

This file has to be executable, i.e. chmod a+x filename. Then create a file by the name StartupParameters.plist with the following contents:

Code:
{
  Description     = "Name of your service goes here";
  Provides        = "Whatever your service provides goes here";
  Uses            = "Disks";
}

Another thing, can it be a simple text file placed in the directory? What is the second bit of code doing and is it necessary? I know the chmod has to do with permissions so I'm sure I can find info on how to do that through the terminal.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.