Startup program execution under other username

aicul

Registered
I am an absolute novice to unix and don't believe that my university unix back from the 80 is very fresh.

I would need help to do the following:

Automatically set a program to run a specific program under a specific user (probably not the one loggin in) at mac stratup time.

Any help most welcome
 
What's the program; it might make it simpler to set up ? What's the user, root, or another regular/admin user ? Does the program have a graphical interface or is it just a shell program ?
 
What's the program?
-> iTunes

What's the user, root, or another regular/admin user ?
-> user called BOSS with admin privileges. But if required a new user can be created.

Does the program have a graphical interface or is it just a shell program ?
-> it has a GUI
 
Aah. Are you starting iTunes as 'boss' just to gain access to their music library, preferences, or something like that ?
 
We all know of those methods to share iTunes by faking common directories.

I want to start iTunes under boss so that I can access my music from any airport based mac using the itunes sharing option.

I really need to know if I can avoid manually logging into boss every morning just to start iTunes.
 
Login to the terminal as the BOSS user.

Then type "open /Applications/iTunes.app". does the GUI open visibly for you? Does that get you the permissions you need within iTunes?

Assuming that works, you can then turn this into a shell script and set it up as a cron. (...there is lots of info on this site on scripts/cron... just Search.)
 
Actually Tommy, that doesn't work. When you start iTunes from the terminal after su-ing to someone else, it just opens the preferences of the user logged in at the con (which I admit is a little strange).

Sorry aicul maybe I'm a little slow. You want to share your own music over AirPort, why do you need to login to anyone other than yourself ? Are you prevented from starting iTunes in your account limtations or something ?
 
We have setup a central unique household iTunes library under the boss account. We use our personal accounts to access iTunes using the music sharing option. This only works if the iTunes that "owns" the music is active. Hence we need to have boss to activate iTunes.

I tried the unix open this does open iTunes. But as for putting it into cron, my poor unix knowledge is slowing me down.
 
Yeah the unix open thing works, but as I tried it, it opened MY music library and not the user that I'd logged into the shell as.

The best solution I can think of for this is situation is to have the boss use own the main music directory, and make it file permissions 777. Then use the unix tricks that everybody knows to point every one else's itunes folder to bosses. That way any user that opens itunes will share all the music, and music imported by any user will go to the boss music library.
 
michaelsanford said:
use the unix tricks that everybody knows to point every one else's itunes folder to bosses.

Yes, BUT,this does not work if you have a Airport connection and just want to use iTunes. It requires that you connect to the server as a defined local user. If you use the iTunes music sharing facility no local user is required on the server iTunes machine.

Ok, if iTunes cannot be lauched from shell under a specified account is this option possible (even if not ideal):-

At startup, iMac AUTOMATICALLY logs into a specific account (BOSS), starts iTunes (ok using syst. prefs/accounts/startup items) and then switches to the login dialog box.
 
aicul said:
Yes, BUT,this does not work if you have a Airport connection and just want to use iTunes. It requires that you connect to the server as a defined local user. If you use the iTunes music sharing facility no local user is required on the server iTunes machine.

Ok hang on. You mean the people who share your music over iTunes don't even have accounts on your machine ? Does anyone besides boss ? If not why do you even want to log out of your account (or at least go to the login screen) ?

If you wanted to do soemthing like that you can set boss to auto-login, then to start iTunes hidden on login, then just go back to the login screen manually with fast user switching.

Keep in mind that if you have some kind of script that causes iTunes to start and logs you back to the login screen when boss connects, it will always run when boss connects and will never let you do anything other than run itunes and return to the LS. I assume this is a security concern, so the only way to prevent that would be to display a message of some kind asking if you wanted to log out.

That's feasible but kind of clumsy.

PS I've looked through the AppleScript dictionaries and can't find any way of returning the user to the login screen. You can log out completely (System Events:power:logout) but not switch to the login screen. and to make it worse, Fast User Switching doesn't have a dictionary, or at least, doesn't have entries in other dictiontaries.
 
I actually want to something real simple. Use iTunes as it is supposed to work. Everyone proposes the unix method. But, lets face it, iTunes is not designed to have its DB hacked this way.

Look at it this way. If one could run iTunes in the background and use iTunes music sharing, wouldn't it be that much easier for the mac user that doesn't know unix?

Must I conclude that unix is not capable of doing everything (a statement I so often hear regards to unix).
 
You can use the su command to run any program under somebody else's permissions. I didn't try it, but the following should work for you:

su boss open /Applications/iTunes.app

For details, use info su from the command line. Hope this helps :)
 
Ok, here's the method that will work. Similar to the above, but you run the iTunes application directly in the terminal. This does run the application as the user issuing the commands rather than the one logged in:

sudo -b -u BOSS /Applications/iTunes.app/Contents/MacOS/iTunes

(Just so y'all know, the -b option runs the given command in the background, returning the prompt to you, and the -u username option lets you run the command as a user other than root.)

And I know this does definitely work - I've been using that to use SubEthaEdit to edit files only root has access to for a while now. ;)
 
Yes, it does. Make sure you're using the full path. Not just /Applications/iTunes.app, but /Applications/iTunes.app/Contents/MacOS/iTunes - it won't work if you just give it the path to the application bundle.

If you want visual confirmation, choose two different appearance schemes for the two users - put one as using Graphite and the other as the default Blue scheme. You'll see the difference in the buttons on the window (one user will have colored buttons, the other will have graphite buttons).

You can also use ps to see that the app is being run as the other user.
 
I tried it using the FULL path. one user (limited, used at parties etc for music) on my machine has one song in their library (don't know where it came from really), and access the rest through sharing. my normal account has the music in itunes. from my normal account (other user is not allowed to sudo) i tried your method, it didnt work.
 
Darkshadow said:
sudo -b -u BOSS /Applications/iTunes.app/Contents/MacOS/iTunes
I have tried the proposed sudo command and it did not work. For your information I first added the user that I used to do sudo in the sudoers file with all privileges.

Have you tried this on your iMac or is your proposal based on your SubEthaEdit experience. :eek:
 
I tried it with iTunes. Works for me. That's odd. Though I didn't add the user to the sudoers file. It still worked out.

Hmm, I just noticed something. Do you guys already have iTunes running? If you do, it doesn't let you run another instance of it (as another user or as the user already running it - just won't let you run two instances). If you do, quit it, then do the command again.

I do this sort of thing all the time. Not just with SubEthaEdit, but with various apps as I need. Most interesting to do is to run System Preferences as another user. ;)

Hmm, here's a screen shot - System Preferences running as the logged in user (one in the background) and it running as another user. Also part of the terminal showing the commands (ignore the two lines saying iTunes quit, that was from me trying to run two of 'em at once).
 

Attachments

  • 2apps2users.jpg
    2apps2users.jpg
    92.9 KB · Views: 9
Back
Top