Posted on 08-01-2012 10:46 AM
I created an AppleScript that add AD Group based on the Computer prefix. When I run it on a 10.6.8 Mac I get an error email. The error is an osascript error. Doing some research I have found that there is a big in AppleScript 10.6 witch has to do with 64bit vs 32. Has anyone else had this error how have they handled it?
Also, how do I write a script that runs based on computer prefix with out using smart groups? What I looking to do is set AD Group based on computer name prefix.
Posted on 08-01-2012 12:13 PM
AppleScript generally must run under a logged in user account. If you're trying to do this while no one is logged in then your script will more than likely fail.
Shell scripting would be better suited for scripting non-user settings. Are you able to convert your work to a shell script (not using osascript)?.
Posted on 08-01-2012 12:36 PM
Agreed with talkingmoose. Applescript is not the best language for what you're trying to do here.
But... to (hopefully) answer your question, the error you're referring to is I think related to older scripting additions being called in the Applescript which can't run in 64 bit mode. I used to see this on older versions of OS X. You may be able to get around it by force specifying the architecture the osascript should run in, such as-
arch -i386 osascript path/to/applescript
which forces it into 32 bit mode. I'm not really sure if this will work in Snow Leopard though.
See this link for more info - http://www.creative-workflow-hacks.com/2010/03/10/64-bit-issues-running-osascript-from-terminal/
Anyways, look into a shell script for your AD group script.
Posted on 08-01-2012 03:21 PM
I have been working on converting the AppleScript. This is what I have so far
ComputerName=scutil --get ComputerName
if [[ "ComputerName" = MAC ]]
then
[ "$Admin" = "Admin01" ]
echo"Is MAC"
fi
if [[ "ComputerName" = MBP ]]
then
[ "$Admin" = "Admin02" ]
echo"Is MBP"
fi
/usr/sbin/dsconfigad -groups "AdminX","$Admin"
anyone know if this would work. I can send you my AppleScript if would like to convert it
Posted on 08-02-2012 09:20 AM
Maybe posting your AppleScript would help us understand the method you're trying to follow.
This is how I'd write the shell script:
ComputerName=$( scutil --get ComputerName )
if [ $ComputerName="MAC" ] ; then
Admin="Admin01"
echo "Is MAC"
fi
if [ $ComputerName= MBP ] ; then
Admin="Admin02"
echo "Is MBP"
fi
/usr/sbin/dseditgroup -o edit -a "DOMAIN$Admin" -t group admin
When declaring a variable, such as setting Admin to "Admin01" you don't need to add the "$". You'll only add "$" when reading the variable later.
Also, using the backticks in the first line was not wrong. I've just written this differently. Sometimes I can confuse the backticks with apostrophes or quotes. Writing it as I've done above just helps me see things more clearly.
Finally, you don't want to use dsconfigad. Instead, you want dseditgroup. The "admin" at the end of the line is the name of the local group where you want to add the directory group. Be sure to replace DOMAIN with your organization's domain name.
I haven't double-checked my work but this should get you going in the right direction.
Posted on 08-02-2012 12:13 PM
This is the AppleScript I am working with
set computerName to (do shell script "scutil --get ComputerName")
if (computerName contains "MB") then
set MBPAdmin to "MBPMACADMIN"
end if
if (computerName contains "MBP") then
set MBPAdmin to "MBPMACADMIN"
end if
if (computerName contains "MP") then
set MBPAdmin to "MBPMACADMIN"
end if
set computerName to do shell script ("sudo dsconfigad -groups ADMIN01," & MBPAdmin) with administrator privileges
What I am looking to do is to have the script be able to find the prefix and then set the AD Group based on the prefix
Posted on 08-02-2012 01:02 PM
Your prefix appears to vary between two and three characters. To standardize this can you use the first three characters? (I don't know what you consider a prefix.)
Something like this should work:
COMPUTERNAME=$( scutil --get ComputerName | cut -c 1-3 )