# Startup program execution under other username



## aicul (Oct 7, 2004)

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


----------



## michaelsanford (Oct 14, 2004)

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 ?


----------



## aicul (Oct 15, 2004)

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


----------



## michaelsanford (Oct 16, 2004)

Aah. Are you starting iTunes as 'boss' just to gain access to their music library, preferences, or something like that ?


----------



## aicul (Oct 18, 2004)

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.


----------



## TommyWillB (Oct 18, 2004)

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.)


----------



## michaelsanford (Oct 18, 2004)

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 ?


----------



## aicul (Oct 20, 2004)

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.


----------



## michaelsanford (Oct 25, 2004)

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.


----------



## aicul (Oct 26, 2004)

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.


----------



## michaelsanford (Oct 26, 2004)

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 Eventsower: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.


----------



## Mrs_suzette (Oct 27, 2004)

Mrs_suzette you should log out before leaving your internet cafe PC. - aicul


----------



## aicul (Oct 27, 2004)

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).


----------



## rhg (Oct 27, 2004)

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


----------



## Darkshadow (Oct 27, 2004)

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.


----------



## Pengu (Oct 27, 2004)

I just tried that Darkshadow. it does nothing.


----------



## Darkshadow (Oct 27, 2004)

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.


----------



## Pengu (Oct 27, 2004)

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.


----------



## aicul (Oct 29, 2004)

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.


----------



## Darkshadow (Oct 29, 2004)

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).


----------



## Pengu (Oct 30, 2004)

> 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).



Wrong. The whole point of this discussion is to automate something that already works. we already know that you CAN have itunes running for two different users. one shares, the other sees it and can play.


----------



## Darkshadow (Oct 30, 2004)

I mean it won't let you run two instances _this way_.  The second iTunes will just quit (and make the first one active) when you try doing it like this.  I know you can have more than one running with fast user switching.

Besides, if you open the one with the music, you don't _need_ to open another one just to share those - you can play them directly.


----------



## aicul (Nov 1, 2004)

I'll give your proposal a new try. Maybe I did something silly. Bare with me please..


----------



## g/re/p (Nov 1, 2004)

Mrs_suzette said:
			
		

> Mrs_suzette you should log out before leaving your internet cafe PC. - aicul





lmao


----------



## aicul (Nov 9, 2004)

I have spend some time trying, trying and trying. As you may have guessed I did not succede to start iTunes using the proposed sudo -b -u command.  

To say the truth iTunes did start if I ran the command from the BOSS account using sudo -b -u BOSS. However, all of the functionalities of iTunes were not available. Particularly the one I need, Music Sharing.   

Any further suggesstions are welcome. Othewise thanks for the time and advice.


----------



## profx (Nov 9, 2004)

i think applescipt may be a better option

have the computer login automatically as BOSS
then a startup applescript that launches itunes and then logs out (fast user swtiching)
hopefully then the computer will be at the login screen, with itunes running in the background under user account boss


----------



## aicul (Nov 9, 2004)

profx said:
			
		

> ... and then logs out (fast user swtiching)
> hopefully then the computer will be at the login screen, ...



An earlier statement indicated that switching to the login screen with applescript was not possible. Are you aware of a way to do this?


----------



## profx (Nov 9, 2004)

Ok, i did some research and here we go. I have tested this and it works.

Add this applescript to your startup items and your away!


```
tell application "iTunes"
	activate
end tell
do shell script ("/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession -suspend")
```

Obviously you have to have the computer automatically log in on startup in the account boss, then the script will run, launch itunes and then put you back to the login screen leaving itunes running happily in the background.


----------



## aicul (Nov 11, 2004)

Super, wonderful, this works!      !

Just for the completeness, there is a catch. Whan you shutdown the Mac it suddenly screams that some other user is still logged in. What I did was to have BOSS do my backups sometime late night and auto-shutdown afterwards. So now family will login/logout only and music is available.

Thanks to all for the input - took some time - but worth it.


----------

