Hi,
I need to set up a laboratory of 15 imacs and have one network drive map for when the students log on.
The imacs are bound to the domain and the students will be using their AD credentials.
I found the “Launch Login Items For All Users at Startup” script at
http://macscripter.net/viewtopic.php?id=33730
First of all I wrote the script to actually mount the drive and tested this.
This worked fine.
tell application “Finder”
try
mount volume “afp://10.0.151.11/Current%20Work”
end try
end tell
I then copied and pasted the code from the URL above into AppleScript Editor and compiled it.
global myName
on run
set launchItemsPath to (path to me as Unicode text) & “Contents:Resources:LaunchItems:”
set myName to getMyName()
logToSystemLog("Started Running login items...")
try
-- make sure the folder exists and continue script if it does
alias launchItemsPath
tell application "Finder"
set launchItems to (files of folder launchItemsPath) as alias list
end tell
repeat with anItem in launchItems
try
-- if its executable then we execute it
set isExecutable to do shell script "if [ -x " & quoted form of POSIX path of anItem & " -a ! -d " & quoted form of POSIX path of anItem & " ]; then echo 'true';fi"
if isExecutable is "true" then
logToSystemLog("Executing: " & POSIX path of anItem)
do shell script quoted form of POSIX path of anItem & " &"
else
-- if it's not executable we determine its kind
tell application "Finder" to set theKind to kind of (contents of anItem)
--return theKind
if theKind is "Alias" then
tell application "Finder" to set theKind to kind of (original item of (contents of anItem))
end if
-- we launch it based on its kind
if theKind begins with "script" or theKind begins with "compiled script" then
logToSystemLog("Running Applescript: " & POSIX path of anItem)
run script (contents of anItem)
else
logToSystemLog("Opening: " & POSIX path of anItem)
--tell application "Finder" to launch (contents of anItem)
do shell script "/usr/bin/open " & quoted form of POSIX path of (contents of anItem)
end if
end if
on error theError number errorNumber
set errorText to "Error: " & theError & " Error Number: " & errorNumber
logToSystemLog(errorText)
end try
end repeat
on error theError number errorNumber
set errorText to "Error: " & theError & " Error Number: " & errorNumber
logToSystemLog(errorText)
end try
logToSystemLog("Finished Running login items...")
end run
on logToSystemLog(theText)
do shell script "/usr/bin/logger " & quoted form of (myName & space & theText)
end logToSystemLog
on getMyName()
set myPath to path to me as Unicode text
if myPath ends with “:” then
set n to -2
else
set n to -1
end if
set AppleScript’s text item delimiters to “:”
set myName to text item n of myPath
if (myName contains “.”) then
set AppleScript’s text item delimiters to “.”
set myName to text 1 thru text item -2 of myName
end if
set AppleScript’s text item delimiters to “”
return myName
end getMyName
I then carried out the instructions below as mentioned.
– save this code as an application bundle
– create the folder “Contents:Resources:LaunchItems:” inside the application bundle
– place items you want launched in that folder
Once having completed the steps above, running the application manually works as expected however nothing happens when the mac is re-started.
Am I missing something? Do I have to ammend the script above or anything else so the OS knows to run this script on Startup?
The imacs are running 10.6.7. Will the script work on this version of the OS?
I have to admit that I was given this problem to solve but have never used AppleScript or any other scripting language before so apologies in advance for my ignorance. I have just ordered an AppleScript book so this should slowly change over the coming weeks and months.
Any help offered or any ideas on getting over this would be very much appreciated.
Kindest Regards
Neil
Model: imac
AppleScript: 2.3 (118)
Browser: Safari 533.20.27
Operating System: Mac OS X (10.6)