Results 1 to 4 of 4

Thread: Login Script

  1. #1

    Member Since
    Aug 13, 2009
    Login Script
    I have created an AppleScript which I intend to run automatically whenever a user logs in.

    It must run for each user, as it requires their username to create a folder with their username as its name on an external drive, so running it from the /Library/StartupItems folder is not an option.

    Adding it to the System Preferences/Accounts/Login Items is also not viable, since the computers are on a network with over 1000 users, so that would take ages to do on each of the 21 computers.

    Is there a way I can get the .scpt or .app file to run during the login process? I have tried creating a logon hook, but that didn't work.
    Elongated Terminology Promotes Vocabulary Development

  2. #2

    Sur3Mac's Avatar
    Member Since
    Aug 03, 2009
    The Netherlands
    Late 2011 MBP 13" i5/16GB RAM,Early 2007 MB white 13", 2x TV 3rd Gen, ᣦ
    Did you try the login hook in Terminal?

    And why didn't that work? Did you get an error message?
    If you did...What did it say?

  3. #3

    Member Since
    Aug 13, 2009
    I added the loginhook through terminal, as per the instructions in the following link:
    Mac OS X: Creating a login hook

    The AppleScript code is:
    tell current application
    	set userName to do shell script "whoami"
    end tell
    tell application "Finder"
    	--Check that the Safe folder exists
    	set drv to "Drive01"
    	if not (exists folder (drv & ":Safe")) then
    		make new folder at drv with properties {name:("Safe")}
    	end if
    	set safe to drv & ":Safe"
    	set posixSafe to "/Volumes/" & drv & "/Safe"
    	tell current application
    		do shell script ("chmod 777 " & posixSafe)
    	end tell
    	--Move other folders on drive to Safe folder
    	set folderList to {}
    	repeat with currentFolder in disk drv
    		--Check name of folder
    		if not (get name of currentFolder = "Safe") then
    			--Add to move list
    			copy name of currentFolder to end of folderList
    		end if
    	end repeat
    	--Get length of list
    	set folderLength to length of folderList
    	--Cycle through list and move unwanted folders
    	repeat with i in folderList
    		move folder (drv & ":" & i) to folder (safe)
    	end repeat
    	--Check that the user folder exists in the safe folder
    	if not (exists folder (safe & ":" & userName)) then
    		--Create the user folder in drv
    		make new folder at drv with properties {name:(userName)}
    		--Move the user folder from safe to drv
    		move folder (safe & ":" & userName) to folder (drv)
    	end if
    	if not (userName = "admin") then
    		--Set denied permissions on the safe folder
    		tell current application
    			do shell script ("chmod 770 " & posixSafe)
    		end tell
    	end if
    end tell
    There is no error message for the .scpt file when it is set up as a loginhook. Nothing happens to the folders in the drive "Drive01".

    The error message for the .app file when used as a loginhook is:
    Can't get some object
    Which doesn't look like a helpful error message, but if somebody knows what it means I'll be eternally greatful.
    Elongated Terminology Promotes Vocabulary Development

  4. #4

    Member Since
    Aug 13, 2009
    I think I have figured it out - the app is being run by the loginhook BEFORE the drive is mounted.

    If I can get the .app to autorun when the drive is mounted, that would do what I need it to do, but I hear OS X does not have a built-in autorun feature.

    Is there any way to run an app or scpt from the built in hard drive when a USB storage device is mounted?

    Or is there any way to mount the drive before the user logs in?


    I have found out how to mount the USB drive before login at the following url:
    Automatically Mount a USB Drive Before Login on Mac OS X

    The app now runs in the loginhook without errors, but it is using the root user to create a folder on the drive, instead of the logged-in user.

    I'll keep searching for an alternative to the "whoami" command, but I've almost got this sorted out.
    Elongated Terminology Promotes Vocabulary Development

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. launchd script not running for user login in OS X Tiger 10.4.11
    By Lateralus138 in forum Switcher Hangout
    Replies: 0
    Last Post: 03-15-2015, 03:19 PM
  2. Run a script at login?
    By thermidor in forum OS X - Operating System
    Replies: 2
    Last Post: 08-21-2007, 08:31 PM
  3. Script to delete plist at login?
    By maulrat1967 in forum OS X - Operating System
    Replies: 3
    Last Post: 04-07-2007, 12:34 PM
  4. creating script for system login
    By pbook24 in forum Schweb's Lounge
    Replies: 3
    Last Post: 01-30-2006, 04:14 PM
  5. I need to replace my login script @ usr/login/bin
    By Bo Eddy in forum OS X - Operating System
    Replies: 1
    Last Post: 05-11-2004, 02:16 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts