Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Run a script at login for all users

Hi, i have a simple apple script that needs to be run at login, i know i can go into system preferneces and go logon items but i need ALL users and im bound to AD so therefore that is not an option. This script needs to work with 10.7.x any help or advice would be muchly appricated.

MacBook Pro, Mac OS X (10.7.3), 128 SDD, 500GB 7500rpm HDD, 8GB RAM

Posted on Jul 16, 2012 8:05 PM

Reply
7 replies

Jul 16, 2012 9:18 PM in response to hoarebags

Can you clarify a few things? Does the script need to be run as the user in question, or could it be run as root? Does the script need to be run at login, or could it be running at startup? Do you need to support fast user switching, and, if so, how would that impact your script?


You could add plist files to /Library/LaunchAgents to run at login. You should be able to configure this through Active Directory, but I don't know anything about that. You could ask about that in the Windows Compatibility forum. You may have to use the dscl tool to manually specify the login script on the server.

Jul 16, 2012 11:03 PM in response to hoarebags

Assuming you have some access to the machine, put the script somewhere (anywhere, really) and create a launchd .plist file in /Library/LaunchAgents/


LaunchAgents run at login. LaunchAgents in a user's home directory (e.g. ~/Library/LaunchAgents/) run when that user logs in, but LaunchAgents in /Library/LaunchAgents run when any users logs in.


Note, though, that LaunchAgents are usually geared towards shell scripts or executables, not AppleScripts, per se. You'd need to look at your script actions to work out the best implementation.

Jul 17, 2012 5:23 AM in response to hoarebags

copy the following into a plain-text editor, change line 12 to the path to your applescript, and save it as user.script.runatload.plist in /Library/LaunchAgents (that's the LaunchAgents folder in the Root directory, not the one in your user directory). this will run the script for any user just after they log in.



<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">

<plist version="1.0">

<dict>

<key>RunAtLoad</key>

<true/>

<key>Label</key>

<string>user.script.runatload</string>

<key>ProgramArguments</key>

<array>

<string>osascript</string>

<string>/path/to/script.scpt</string>

</array>

</dict>

</plist>

Jul 17, 2012 5:37 PM in response to hoarebags

hoarebags wrote:


its a pretty basic applescript all it is, is a script that mounts some network drives for me, so would i still be able to make this into a .plist file ? if so how do u make a .plist file?

You don't even need a login script for that. You can setup autofs to mount those network drives on demand. Here are full details on that: http://images.apple.com/business/docs/Autofs.pdf


An easier, but less elegant, option is to manually mount the drives you need and make sure to save your user account and password in your keychain. Then, for each mounted drive, create a Finder alias to the drive. Drag the drive (or any folder inside the drive) to some location on your startup disk while holding down option and command. What you will get from that is a Finder alias that is smart enough to mount the network share when you double-click on it. You can even create aliases to folders and files inside a mounted network drive and when you open the alias it will automatically mount the network drive where the original lives.

Run a script at login for all users

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.