Is there a way to run a GUI app, like iTunes, when not logged in to a computer directly? Thus, I'd like to be able to start a program, then log out, or (preferably) run a GUI program directly from an SSH session when no user is logged in to the console itself.
(Note that I'm not looking for a music player in particular, but a general method of running GUI programs.)
You need to set up a VNC server and connect using a client or buy the Apple Remote Desktop.
This does not work for GUI apps. There are some command line apps that will play music etc. but not iTunes.
If you have a machine that is headless and you can hit it with VNC or Screen Sharing to log in, then you can use open /Applications/iTunes.app to launch application from ssh in the current users GUI with out logging in to the GUI. However you need the right permissions.
You can combine setatakahashi's answer above with OS X's fast user switching, since you mentioned that you were prepared to first log into the machine you would like to control.
Log in to the machine you want to control. Fire up a VNC server like OSXVNC and set the port to 5902 or something of your choice that isn't the default 5900 used by the VNC server included in all Leopard Macs. (And which can be enabled by any admin user: Sharing pref pane=>Screen Sharing=> Allow VNC client to connect.) Set a password.
Enable fast user switching (Accounts pref pane=> Login options) and then, from the FUS icon in the menubar, choose "Login Window". The computer will then present Mac OS X's login window and allow others to log in and out normally without interrupting your session. (If the machine's preferences are set to display empty name and password fields, your active, hidden session will likely go unnoticed till someone logs in and clicks the FUS icon.) Your console session remains active, as does your VNC server. You can now control that session using a regular VNC client pointed at the right port on the remote machine. JollysFastVNC is a good, fast choice if your controller's also a Mac.
There are many security considerations, starting with a strong recommendation to use an SSH tunnel. Each account on the remote machine needs a password to stop users switching willy-nilly, users can kill your session by shutting down, sleeping, etc. Reliance on a wireless network might kill your connection, depending on how things are set up. The other stuff is probably outside the scope of this question. :)
Is the computer running truly headless (as in WindowServer is never started - usually Xserves) or is it simply a computer that doesn't have a user logged into?
The short answer is no. Mac OS X 10.5 will specifically disable applications from opening up and running over top of loginwindow. (Which was a rather annoying security hole when installers cough Flash cough would open a Finder window over loginwindow giving anybody walking by root access)
Sure:
I don't know if that works on OS X, since I'm a Linux user, but give it a try. Also, if you're going to do this outside a LAN (fast connection), try NoMachine.
I'm afraid this question will be closed do, given that it's not really sys admin related... let's hope not.
Oh, and I'm sure there are several good VNC apps for the Mac, so that's another option.
Also, take a look at DynDNS in case you have a dynamic IP and need access over the Internet.
You might be able to open the app up with the open command line command.
open /Applications/iTunes.app
You might also want to look into Automater or AppleScript to do these kinds of actions.