Run command at logon?

Discussion in 'macOS' started by SlickShoes, Feb 1, 2011.

  1. SlickShoes macrumors 6502a

    Jan 24, 2011

    I want to run a command in terminal when a user logs on to the machine.

    Here it is:

    dseditgroup -o edit -u admin -P password -t user -a "$USER" _developer

    It adds the currently logged on user to the developer group. I need this to run at logon as I run labs in a university i can never tell who will log on to which computer so cant make this a permanent change manually.

    If anyone can throw me a bone here that would be awesome.
  2. belvdr macrumors 603

    Aug 15, 2005
    No longer logging into MR
    In a normal Unix environment, you'd place this in /etc/profile or /etc/bashrc.
  3. larkost macrumors 6502a

    Oct 13, 2007
    While you could do this with either a loginhook (reasonable) or a launchdaemon[1], I think you are missing a much better solution: add your LDAP users group (I am presuming LDAP/AD) nested in your _developer group. That way anyone who logs in from that group is automatically seen as being part of that group. That way you are not constantly messing with your dslocal domain.

    [1] If you really have to do this as a launchd item, then you probably need to do this with a launchdaemon with its LimitLoadToSessionType key set to Aqua. This will run it as root, but run when things go into an Aqua session. This will work with console logins, but not ssh logins. But you are going to have to go through some gyrations to get the user name (look at the owner of the loginwindow process), and things get complicated if you enable fast user switching (my advice is to disable this for a lab).
  4. SlickShoes thread starter macrumors 6502a

    Jan 24, 2011
    Your suggestion above, i take it that means that anyone logging in via Active Directory will be put in the developer group? That sounds like it is definately the way to go, i will try and look into doing that first before getting into those other solutions.

    Also you are correct about fast user switching i always have that turned off for my labs!

    Thanks for the help guys!

Share This Page