Caper policy and AppleScript

j99mac
Contributor

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.

6 REPLIES 6

talkingmoose
Moderator
Moderator

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)?.

mm2270
Legendary Contributor III

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.

j99mac
Contributor

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

talkingmoose
Moderator
Moderator

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.

j99mac
Contributor

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

talkingmoose
Moderator
Moderator

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 )