I’m working on a script that we plan to use at a university that will install Symantec AntiVirus but will first check if Norton AntiVirus is installed first (different corporate versions). I was trying to do this by checking for the existance of a receipt named “Norton AntiVirus.pkg” but it doesn’t seem to be working.
Can anyone tell me what I am doing wrong?
set pathToNav to "/Library/Receipts/Norton\\ AntiVirus.pkg"
display dialog "Do you want to install Symantec Antivirus?" buttons {"No", "Yes"} default button 2
if button returned of result is "Yes" then
tell application "Finder"
if exists POSIX path of pathToNav then
display dialog "Older version of NAV is installed. We need to uninstall first" buttons {"Cancel", "Ok"} default button 2
if button returned of result is "Ok" then
do shell script "open /Volumes/MacSetup/SymantecUninstaller.app" --Is there a better way I should be opening?
end if
end if
end tell
if not (exists POSIX path of pathToNav as string) then
do shell script "installer -pkg /Volumes/MacSetup/SAVinstall.mpkg -target /" with administrator privileges
end if
end if
I’ve tried several different ways to get it to look for that file (package) but I haven’t been able to find the answer.
Thanks.
Can you be a bit more specific about how it fails? Is there an error message of any kind?
It is not properly determining if the file exists. This script just stops and does not run any installers like I want it to.
Basically, my question is, what is the proper way to have an applescript see if a certain file (or .pkg) exists?
Here is my event log:
tell current application
display dialog “Do you want to install Symantec Antivirus?” buttons {“No”, “Yes”} default button 2
{button returned:“Yes”}
end tell
tell application “Finder”
exists “/Library/Receipts/Norton\ AntiVirus.pkg”
false
end tell
tell current application
exists “/Library/Receipts/Norton\ AntiVirus.pkg”
true
end tell
Thanks.
I would try something like this:
display dialog "Do you want to install Symantec Antivirus?" buttons {"Cancel", "Install"} default button 2
try
-- The receipt must exist to make an alias. If it doesn't exist, an error is thrown.
get ((path to library folder from local domain as Unicode text) & "Receipts:Norton AntiVirus.pkg") as alias
display dialog "An older version of NAV is installed; We need to uninstall that first." buttons {"Cancel", "Uninstall"} default button 2
activate application "MacSetup:SymantecUninstaller.app"
on error number errNum
if errNum is -128 then
-- The user canceled the dialog
error number -128
else
do shell script "/usr/sbin/installer -pkg /Volumes/MacSetup/SAVinstall.mpkg -target /" with administrator privileges
end if
end try
Thank you so much. This works great.
display dialog "Horray"
I’m trying to go a bit deeper with this script. I can’t seen to get it to check for the existence of 3 things.
I would like it to first check if Norton Antivirus.pkg is in reciepts, if it is, run SymantecUninstaller (this part works), if Norton Antivirus.pkg is not in receipts, check for Symantec AntiVirus.pkg, if installed, install savPrefs.mpkg. If all 3 are install, just display dialog.
I’m getting stuck at what to put after the first “error number -128”
display dialog "Do you want to install Symantec Antivirus?" buttons {"Cancel", "Install"} default button 2
try
-- The receipt must exist to make an alias. If it doesn't exist, an error is thrown.
get ((path to library folder from local domain as Unicode text) & "Receipts:Norton AntiVirus.pkg") as alias
display dialog "An older version of NAV is installed; We need to uninstall that first." buttons {"Cancel", "Uninstall"} default button 2
activate application "MacSetup:Packages:SymantecUninstaller.app"
on error number errNum
if errNum is -128 then
-- The user canceled the dialog
error number -128
else --Not sure what to put here
get ((path to library folder from local domain as Unicode text) & "Receipts:Symantec AntiVirus.pkg") as alias
display dialog "SAV already installed."
do shell script "installer -pkg /Volumes/MacSetup/Packages/savPrefs.mpkg -target /"
on error number errNum
if errNum is -128 then
-- The user canceled the dialog
error number -128
do shell script "/usr/sbin/installer -pkg /Volumes/MacSetup/Packages/SAVinstall.mpkg -target /" with administrator privileges
end if
end if
end try
Thanks again for your help.