Hiroto, thank you so much for this script. I almost have it integrated with my active directoy but I am running into a small problem. If I just enter one app into the script it will place it in the dock. If I enter multiple, it will not do all of them and it is not very consistant. Can you recommend a fix? Here is my modified version:
This is what I am using to pull active directory credentials and then call the script if they are in the correct user group:
-- Get the logged in users username
set loggedInUser to do shell script "whoami"
-- Get the Users account UniqueID
set accountType to do shell script "dscl . -read /Users/" & loggedInUser & " | grep UniqueID | cut -c 11-"
-- Get the nodeName from the Users account
set nodeName to do shell script "dscl . -read /Users/" & loggedInUser & " | awk '/^OriginalNodeName:/,/^Password:/' | head -2 | tail -1 | cut -c 2-"
-- Get the Users group membership from AD
set ADGroups to do shell script "dscl " & quoted form of nodeName & " -read /Users/" & loggedInUser & " | awk '/^dsAttrTypeNative:memberOf:/,/^dsAttrTypeNative:msExchHomeServerName:/'"
-- Get the Users AD Home Folder
set ADHome to do shell script "dscl " & quoted form of nodeName & " -read /Users/" & loggedInUser & "| grep SMBHome: | cut -c 10- | sed 's/\\\\/\\//g' "
-- Checks to see if account is an AD Account, if its not exit
if accountType is less than 1000 then
tell me to quit
end if
if ADGroups contains "Technology_Dept" then
run scriptfile "Macintosh HD:Users:Shared:Staff_Drives.scpt"
end if
Then I am am calling this to place the apps in the dock:
--APPLESCRIPT
set apps to {"/Users/Shared/Apps_Drive.app", "/Users/Shared/Apps_Drive.app"}
set apps to {"/Users/Shared/Public_Drive.app", "/Users/Shared/Public_Drive.app"}
set apps to {"/Users/Shared/Stu_Public.app", "/Users/Shared/Stu_Public.app"}
set apps to {"/Users/Shared/H_Drive.app", "/Users/Shared/H_Drive.app"}
set apps to {"/Users/Shared/Lock_Desktop.app", "/Users/Shared/Lock_Desktop.app"}
add_persistent_apps_to_dock(apps)
on add_persistent_apps_to_dock(argv)
(*
list argv : list of POSIX path of application bundles
*)
set args to ""
repeat with a in argv
set args to args & a'squoted form & space
end repeat
do shell script "/usr/bin/perl -CSDA <<'EOF' - " & args & " 2>&1
#
# @ARGV : array of absolute path of application bundles
#
use strict;
use Unicode::Normalize;
# get exisiting paths from persistent-apps in dock plist
my @paths = ();
my $t = qx[defaults read com.apple.dock persistent-apps];
while ($t =~ /\"_CFURLString\" = \"(.*)\";/og) {
$_ = $1;
s/\\x5c{2}U([0-9a-f]+)/pack('U*', hex($1))/ogie;
s/\\x5c{2}\"/\"/og;
push @paths, NFD($_); # normalise to NFD
}
# add given paths to persistent-apps in dock plist
map { s%/*\\z%/%o } @ARGV; # normalise bundle path so that it ends with single /
for (@ARGV) {
my $p = NFD($_); # normalise to NFD
my $re = qr/^\\Q$p\\E\\z/i;
unless (grep /$re/, @paths) { # only if not in persistent-apps
s/&/&/og; # XML escape: & => &
s/</</og; # XML escape: < => <
s/'/'\\\\''/og; # shell escape: ' => '\\''
qx[
defaults write com.apple.dock persistent-apps -array-add '
<dict>
<key>tile-data</key>
<dict>
<key>file-data</key>
<dict>
<key>_CFURLString</key>
<string>$_</string>
<key>_CFURLStringType</key>
<integer>0</integer>
</dict>
</dict>
</dict>'
];
}
}
# restart Dock
qx[killall Dock];
EOF"
end add_persistent_apps_to_dock
--END OF APPLESCRIPT
I am not an expert when it comes to this so if I am doing it wrong, please let me know! Thank you so so so much!