Hey all,
I have a script I need to send to a bunch of computers using Apple Remote Desktop that enables the VNC server and gives it a specified password (don’t ask why ARD can’t do this on its own). The problem is that when I use osascript, variables don’t seem to be remembered. For example, at one point, I store the current user’s short name in a variable to compare it to a string to see if a certain user is logged on (is there a better way to do this?). The problem is that when I send this through ARD with osascript, it doesn’t set the variable. When I run the script locally on the client machine, the following script works perfectly. So what’s with osascript?
osascript <<EndOfMyScript
set currentUser1 to do shell script "whoami"
--If nobody is logged in, log in as USER I WANT TO LOG IN AS
if (currentUser1 is "root") then
--this is because root is the current user when nobody's logged in (is there a better way to do this?)
tell application "System Events"
keystroke "USER I WANT TO LOG IN AS"
keystroke tab
delay 0.5
keystroke "USER'S PASSWORD"
delay 0.5
keystroke return
keystroke return
end tell
end if
EndOfMyScript
osascript <<EndOfMyScript
do shell script "sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -configure -clientopts -setvnclegacy -vnclegacy yes -setvncpw -vncpw HASH GOES HERE" password "SOME PASSWORD" with administrator privileges
EndOfMyScript
osascript <<EndOfMyScript
--Get the current user's short name
set currentUser2 to do shell script "whoami"
--Log out only if the current user is USER I WANT TO LOG IN AS
if (currentUser2 is "USER I WANT TO LOG IN AS") then
tell application "Finder" to activate
tell application "System Events"
tell process "Finder"
keystroke "q" using {command down, option down, shift down}
end tell
end tell
end if
EndOfMyScript