New To Mac-Forums?

Welcome to our community! Join the discussion today by registering your FREE account. If you have any problems with the registration process, please contact us!

Get your questions answered by community gurus Advice and insight from world-class Apple enthusiasts Exclusive access to members-only contests, giveaways and deals

Join today!

 
Start a Discussion
 

Mac-Forums Brief

Subscribe to Mac-Forums Brief to receive special offers from Mac-Forums partners and sponsors

Join the conversation RSS
OS X - Operating System General OS operation information and support

OS 10.4 - Login Script


Post Reply New Thread Subscribe

 
Thread Tools
combatking0

 
Member Since: Aug 13, 2009
Posts: 13
combatking0 is on a distinguished road

combatking0 is offline
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
QUOTE Thanks
Sur3Mac

 
Sur3Mac's Avatar
 
Member Since: Aug 03, 2009
Location: The Netherlands
Posts: 1,563
Sur3Mac is a jewel in the roughSur3Mac is a jewel in the roughSur3Mac is a jewel in the rough
Mac Specs: Late 2011 MBP 13" i5/16GB RAM,Early 2007 MB white 13", 2x TV 3rd Gen, ᣦ

Sur3Mac is offline
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?

QUOTE Thanks
combatking0

 
Member Since: Aug 13, 2009
Posts: 13
combatking0 is on a distinguished road

combatking0 is offline
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:
Code:
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)}
	else
		--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:
Code:
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
QUOTE Thanks
combatking0

 
Member Since: Aug 13, 2009
Posts: 13
combatking0 is on a distinguished road

combatking0 is offline
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?

----------------------------------------edit---------------------------------------

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
QUOTE Thanks

Post Reply New Thread Subscribe


« Same Apple Newsletters Keep Reappearing in Imail | Error 36 when opening a file via afp »
Thread Tools

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread
Thread Starter
Forum
Replies
Last Post
Login Script to Mount SMB Drive to Desktop redbergy OS X - Operating System 12 07-05-2011 04:31 PM
Run a script at login? thermidor OS X - Operating System 2 08-21-2007 08:31 PM
Script to delete plist at login? maulrat1967 OS X - Operating System 3 04-07-2007 12:34 PM
creating script for system login pbook24 Schweb's Lounge 3 01-30-2006 04:14 PM
I need to replace my login script @ usr/login/bin Bo Eddy OS X - Operating System 1 05-11-2004 02:16 PM

All times are GMT -4. The time now is 11:26 AM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
X

Welcome to Mac-Forums.com

Create your username to jump into the discussion!

New members like you have made this community the ultimate source for your Mac since 2003!


(4 digit year)

Already a member?