read AD groups from applescript

Hi.

I’m trying to make a login applescript that work out if the current user is a member of an AD group.

I can get the username, but need to prepend it with "domain"

I can do it with a shell script like this

export user=$(whoami) – get the username
domain_user=$our_domain_name’'$user – prepend the domain and slash
dsmemberutil flushcache – flush the cache
export answer=“$(dsmemberutil checkmembership -U $domain_user -G group_name)”

if [[ “$answer” == not ]]
then
do some stuff here
fi

Ive tried putting this into applescript:

 
try
    set user to do shell script "whoami"
    set TheCommand to "dsmemberutil checkmembership -U " & "our_domain_name\\" & user & " -G group_name"
    do shell script "dsmemberutil flushcache"
    try
         set Answer to do shell script TheCommand
    end try
end try

But the shell command does not see the . how can i get around the escape charater problem? The double slash does not work…

any clues?
Mac OS X (10.7.1)

Hello and welcome to Macscripter! :slight_smile:

Have you tried using quoted form? that puts the stuff within single quotes. and leaves the shell to escape it.


set my shellcommand to quoted form of "export myvar=`my_util ${whomai} 2>/dev/null`"

Please use tags around your code. For shell scripts I think code and /code surrounded by brackets is appropriate. It makes it so much easier to read! :slight_smile:

Hi, thanks for the suggestion, and apologies for the lack of formatting.

It does not seem to work - or i cant make it work…

quoted form of 

does not seem to be able to encapsulate a single \ character.

Might there be a way of using ascii code 92?

cheers.

l.

Hello!

I am sorry for having forgotten all about this in the heat. :frowning:

The script below will produce one slash, as you see I use both a double slash, and quoted form.
I have to do that, since it is an escape character within applescript itself, not only in the do shell script command. This works for one slash, I can’t tell you how you would produce two slashes in a row! :slight_smile:


set a to quoted form of "\\"

do shell script "echo " & a & ">~/Desktop/ch.test"