| OS X - Operating System General OS operation information and support |
| Post Reply | New Thread | Subscribe |
|
|
Thread Tools |
![]() Member Since: Aug 13, 2009
Posts: 13
![]() |
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 | |
![]() Member Since: Aug 03, 2009
Location: The Netherlands
Posts: 1,563
![]() ![]() ![]() Mac Specs: 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?
|
| QUOTE Thanks | |
![]() Member Since: Aug 13, 2009
Posts: 13
![]() |
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
The error message for the .app file when used as a loginhook is: Code:
Can't get some object Elongated Terminology Promotes Vocabulary Development Last edited by combatking0; 09-22-2009 at 03:32 AM. Reason: Added a link to the loginhook setup instructions. |
||||
| QUOTE Thanks | |||||
![]() Member Since: Aug 13, 2009
Posts: 13
![]() |
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 Last edited by combatking0; 09-22-2009 at 05:19 AM. Reason: Added more detail |
| QUOTE Thanks | |
| Post Reply | New Thread | Subscribe |
| Thread Tools | |
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
|
|||||||
Thread |
Thread Starter |
Forum |
Replies |
Last Post |
| Login Script to Mount SMB Drive to Desktop | redbergy | OS X - Operating System | 12 | 07-05-2011 03:31 PM |
| Run a script at login? | thermidor | OS X - Operating System | 2 | 08-21-2007 07:31 PM |
| Script to delete plist at login? | maulrat1967 | OS X - Operating System | 3 | 04-07-2007 11:34 AM |
| creating script for system login | pbook24 | Schweb's Lounge | 3 | 01-30-2006 03:14 PM |
| I need to replace my login script @ usr/login/bin | Bo Eddy | OS X - Operating System | 1 | 05-11-2004 01:16 PM |
All times are GMT -4. The time now is 07:30 AM.
Powered by vBulletin