Well Automator automates tasks but says nothing about how the task will be run. You can create an app, or a folder action, or a service, etc in Automator but that woln;t address the issue of when the code runs.
As you're looking to have something start running at system boot time (I assume that's what you mean by startup in your post above also as you want it available to all users this is really your only option) then you are looking to create what in Unix speak is termed a daemon, something that runs in the background and offers services.
The way to start a daemon running at boot time in OS X is via the Launch Daemon. How comfortale are you with the terminal? Start by looking at the man page for launchd (the name of the Launch Daemon).
Hopefully others will chime in here, my launchd skills are limited.
I'm not sure whether this should be a LaunchDaemon or a LaunchAgent - if it requires user interaction as you sugest it should really be the latter, so that's what I'll show how to do.
Open TextEdit, make sure the open document is set to plain text (not rich text), copy in the following text, then save it as user.bash_script.autostart in the folder /Library/LaunchAgents/. Then restart the machine or load the plist using launchctl in terminal.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
This job will start the script as a daemon so that it's running for all users. The KeepAlive key specifies that if the daemon quits launchd should automatically restart it. It's up to you to make sure users have the correct permissions to quit the process if it gets stuck.
Note: using a LaunchAgent means that a separate instance of this process will be created for each user who logs in, and that the process will not be running if no user is logged in. if you need to have one running instance for all users you need to use a LaunchDaemon. However, LaunchDaemons are not supposed to have user interaction, which it seems like you want. more details would be helpful.
Thank you Frank and twtwtw! I started looking into how to use launchd last night but haven't tried it out yet because I don't have access to the MAC all the time. I think I will need Launch Daemon instead of Launch Agent because I would like my script to be running in the background all the time, once the MAC is powered on, whether there is anyone logged in.
I do wonder if I will end up having to use Launch Agent instead because my script is bascially launching a server listening for requests and firing off Safari once it receives a request to start running a test against Safari. I am pretty new to Safari also (I only know the basic, at the user-level). I am not sure if Safari is user-profile based, and that I will have to have someone logged in in order to open up Safari.
I am planning to try out Launch Daemon either later today or the beginning of next week.
First, pet peeve: It's Mac, not MAC. MAC stands for Media Access Control, a way of identifying your computer on a low level. Mac is short for Macintosh, a kind of apple.
You're in a gray area. LaunchDaemons can't have any GUI access themselves, but I don't think there's anything stopping them from invoking a GUI app. however, Safari is only avaliable in user contexts, not at the root level, so if your script tries to invoke Safari when no users are logged in, I have no idea what will happen. This really sounds more like a LaunchAgent than a LaunchDaemon to me, since (I'm assuming) you'd want to call Safari in a particular user context, not in every user context.
I'll let twtwtw take the lead on this as I said my lauchd experience is limited.
But I do have a question. You wrote that you want the script running even when no one is logged in. Why is that? Will the testing be going on even when no one is logged in? I thought from your previous post that some user interaction will be needed.
The reason I ask is because another possible solution came to me. If the users who will be accessing and using this are know before hand it may be possible to just have the script started from their login items when they log in. Again this would only work if this was only needed when a user was logged in.
Thank you so much Frank! Yeah, I would like my testing to be going on even when no one is logged in. The Mac is going to be a shared machine. It's major use is for running automated website tests, but in the future, we may use it for soemthing else, we don't know yet. We don't need to see the tests running visually, the results are good enough for now.
I really appreicate your another possible solution because we are experiementing now. We may end up going into that direction. It's good to know more and have more ideas.
I am trying out launchd now. I set my LaunchDaemon to run at startup (i.e. I use "<true/> for the key "RunAtLoad") but it only started at startup once (the first time out of the 6, 7 times I tried). I wonder if anyone knows where the log file for launchd is? I cannot see any launchd file under /var/log. I also wonder how I can tell if it's running in Activity Monitor? Thanks!
launchd sends its error messages to the main system log; just open console and you'll see them. Note, however, that launchd has a 10 second throttle period (meaning it won't allow a process to launch at intervals of less than ten seconds), so f you're quitting and restarting rapid-fire that might be the problem.
in activity monitor you can see if you process is running. launchd is always on. if you want to check on the launnchd job itself run launchctl list in terminal.
Thanks a lot twtwtw! launchctl is helpful telling me all the launchd jobs that are running. I added key "KeepAlive" and it resolved the problem of my launchd job not running after the machine restarted (I only used RunAtLoad at first because I was starting up a server which kept listening and was not supposed to end, but there must be something I am missing).