osascript Password Prompt

Hi all,

I’m having some problems running a script to automate a software installation and being prompted for an osascript password. When running the script via AppleScript it prompts for a password too…

First time I’ve seen this so any help would be greatly appreciated.

Thanks

Will

-- Variable to check the version of OS X
set osVersion to do shell script "sw_vers -productVersion"

if osVersion begins with "10.5" then
	set staticText to 1
else if osVersion begins with "10.6" then
	set staticText to 1
else if osVersion begins with "10.7" then
	set staticText to 6
end if

-- Variable for Package Tree testing
set BetaPackage to "Software"

-- Varibale for location of the .dmg
set InspirationPath to POSIX path of (path to desktop) & "Packages/" & BetaPackage & "/Inspiration 9 Download/installer/Inspiration-9-ESD.dmg"

-- 2 second delay variable
set delayPeriod to 2

-- Variables for keystroke commands
set tabKey to ASCII character 9
set returnKey to ASCII character 13

-- Read serial number from fields.ini
set filePath to POSIX path of (path to desktop) & "'Packages/" & BetaPackage & "/Inspiration 9 Download/meta/fields.ini'"
set ShellScript to do shell script "cat " & filePath
set serialLine to paragraph 2 of ShellScript
set serial to (characters 10 through -1 of serialLine) as text
set serialLine3 to paragraph 3 of ShellScript
set customerName to (characters 13 through -1 of serialLine3) as text

-- Mount the .dmg if not already mounted
tell application "Finder"
	if not (exists "Inspiration 9 IE") then
		do shell script "hdiutil attach " & quoted form of InspirationPath
	end if
end tell

-- Tell the Shell to copy the application to Applications
do shell script "sudo cp -fRv /Volumes/Inspiration\\ 9/ /Applications" password "" with administrator privileges

tell application "System Events"
	tell process "SecurityAgent"
		if group 1 of window 1 exists then
			keystroke returnKey
		end if
	end tell
end tell

delay delayPeriod

-- Tell the shell to remove the additional Applications alias
do shell script "sudo rm /Applications/Applications" password "" with administrator privileges

delay delayPeriod

-- Unmount .dmg and create shortcut on Desktop
tell application "Finder"
	do shell script "hdiutil detach '/Volumes/Inspiration 9'"
	delay (delayPeriod + 1)
	make new alias to file "Inspiration 9 IE.app" of folder "Applications" of startup disk
	delay delayPeriod
end tell

delay delayPeriod

-- Add application to Dock
do shell script "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/Inspiration 9 IE.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"

delay delayPeriod

-- Refresh Dock
do shell script "killall -HUP Dock"

delay delayPeriod

tell application "System Events" to tell UI element "Inspiration 9 IE" of list 1 of process "Dock"
	if not (exists) then return
	-- Right click on Dock icon
	perform action "AXShowMenu"
	-- Click Open to launch application
	click menu item "Open" of menu 1
end tell

-- Enter user details
try
	tell application "System Events"
		tell process "Inspiration 9 IE"
			repeat until exists window 1
			end repeat
			keystroke serial
			delay 0.5
			keystroke tabKey
			delay 0.5
			keystroke customerName
			delay 0.5
			keystroke returnKey
		end tell
	end tell
end try

-- Click Accept to license agreement
tell application "System Events"
	tell process "Inspiration 9 IE"
		repeat until exists window 1
		end repeat
		click button "Accept" of window 1
	end tell
end tell

delay delayPeriod * 2

-- Quit Inspiration
try
	tell application "System Events" to set pid to the unix id of process "Inspiration 9 IE"
	do shell script ("kill " & pid)
end try

delay delayPeriod

do shell script "rm -r ~/Library/Preferences/Inspiration\\ Software" password "" with administrator privileges

delay delayPeriod

do shell script "cp -r ~/Desktop/Packages/Software/Inspiration\\ 9\\ Download/installer/Inspiration\\ Software ~/Library/Preferences/Inspiration\\ Software"

You have do shell script with administrator privileges and not a password added so the machine wil ask you for a password. Nothing more to say about that. It’s part fo the security system in OS X.

do shell script "" with administrator privileges --even this prompts a password

EDIT:

to avoid it you should use:


do shell script "" user name "administrator" password "password"

where the string administrator and password are replaced with the right values of course.

Thanks for the reply.

The problem we have is none of the Mac’s we setup for our customers have a password… Slight hurdle to overcome it seems!

What if you try password “”?