Re: Simple apple script - Beginner Problem
Re: Simple apple script - Beginner Problem
- Subject: Re: Simple apple script - Beginner Problem
- From: "Mark J. Reed" <email@hidden>
- Date: Tue, 14 Jul 2009 10:19:19 -0400
> set UNC to (do shell script "/usr/bin/dscl localhost read /Active\\
> Directory/All\\ Domains/Users/" & user_name & " homeDirectory | awk -F
> \":\" '{print $3}' | cut -c 4-200")
First some nitpicks:
I really think that would be more legible with "quoted form" than the
doubled-backslashed spaces.
set dnPath to "/Active Directory/All Domains/Users/" & user_name
set uncPath to (do shell script "/usr/bin/dscl localhost read " &
(quoted form of dnPath) & "|awk -F: '{print $3}' | cut -c 4-200")
Why the magic number 200? Seems like what you want is just everything
from the 4th character on, no matter how long, right? You can ask for
that with "cut -c 4-", no arbitrary limits required.
But piping awk to cut is kinda silly; cut is mainly for small jobs
where awk is overkill. If you're already firing up awk, might as well
just do everything there:
set uncPath to (do shell script "/usr/bin/dscl localhost read " &
(quoted form of dnPath) & "|awk -F: '{print substr($3,4)}' " )
Now, on to your question:
> Which works a treat except for one thing; with the UNC path returned
> the slashes are the wrong way around, i.e the UNC path returned
> contains back slashes but it needs to be forward slashes for the mount
> command to correctly interpret the input;
1. Which mount command? If you mean the shell one, are you sure it
won't handle the backslash version if you just quote it properly?
2. Replacing the backslashes with slashes can be done any number of
ways. I'd add it as another transformation within the awk program,
but once you're dealing with backslashes inside the quoted string
inside the quoted string, things get confusing, and it's time to reach
for "quoted form" again:
set awkProg to "{path = substr($3, 4); gsub(/\\\\/, \"/\", path); print path}"
set uncPath to (do shell script "/usr/bin/dscl localhost read " &
(quoted form of dnPath) & "|awk -F: " & (quoted form of awkProg))
Or you could change them after the fact within AppleSscript using the
old tried and true TID trick:
set uncPath to (do shell script "/usr/bin/dscl localhost read " &
(quoted form of dnPath) & "|awk -F: '{print substr($3,4)}' " )
set text item delimiters to "\\"
set componentList to text items of uncPath
set text item delimiters to "/"
set uncPath to componentList as text
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden