Installer PKG Script

Discussion in 'Mac Programming' started by gpchess2k, Mar 7, 2017.

  1. gpchess2k macrumors newbie

    gpchess2k

    Joined:
    Oct 12, 2015
    #1
    Hello Everyone,

    Looking for guidance on creating a simple script that will streamline pkg files within an application bundle. I need there to be a progress bar though. Doesnt have to be real-time but needs to stop (alert) when all pkgs have been installed. I know its not possible with AppleScript so my current script below may have to be converted over to bash. Here's what i got in AppleScript thus far:

    Code:
    tell application "Finder"
        set myFolder to (quoted form of (POSIX path of ((path to me) as string))) & "Contents/Resources/Installers/"
    end tell
    
    do shell script ¬
        "installer -allowUntrusted -pkg " & myFolder & ¬
        "autoupdate.pkg -target /" with administrator privileges
    
    do shell script ¬
        "installer -allowUntrusted -pkg " & myFolder & ¬
        "excel.pkg -target /" with administrator privileges
    
    do shell script ¬
        "installer -allowUntrusted -pkg " & myFolder & ¬
        "onenote.pkg -target /" with administrator privileges
    
    do shell script ¬
        "installer -allowUntrusted -pkg " & myFolder & ¬
        "powerpoint.pkg -target /" with administrator privileges
    
    do shell script ¬
        "installer -allowUntrusted -pkg " & myFolder & ¬
        "word.pkg -target /" with administrator privileges
    
    
    tell application "Finder"
        display dialog "Script has completed successfully!" buttons {"Restart", "Cancel"} default button "Cancel" with icon caution
        
        if button returned of result is "Restart" then
            do shell script "(sleep 5 ; shutdown -r now) &>/dev/null &" with administrator privileges
            
        end if
    end tell
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Starting from OS X Yosemite you can use Automatic Progress Indicators to display progress. There's also cocoadialog and others. I'll leave it up to you to include it or not.

    Code:
    --set myFolder to (quoted form of (POSIX path of ((path to me) as string))) & "Contents/Resources/Installers/"
    set myFolder to (quoted form of (POSIX path of ((path to resource "Installers") as string)))
    
    set packageList to {"autoupdate.pkg", "excel.pkg", "onenote.pkg", "powerpoint.pkg", "word.pkg"}
    
    
    repeat with i from 1 to number of items in packageList
        set packageName to item i of packageList
        -- Install the package
        installPKG(packageName, myFolder)
    end repeat
    
    on installPKG(aPackage, installersFolder)
        (*
        do shell script ¬
            "installer -allowUntrusted -pkg " & myFolder & ¬
            "word.pkg -target /" with administrator privileges
    *)
        log "installer -allowUntrusted -pkg " & installersFolder & ¬
            aPackage & " -target /"
    end installPKG
    
    
    set buttonReturned to button returned of (display dialog "Script has completed successfully!" buttons {"Restart", "Cancel"} default button "Cancel" with icon caution)
    
    if buttonReturned is "Restart" then
        --do shell script "(sleep 5 ; shutdown -r now) &>/dev/null &" with administrator privileges
        -- or
        -- delay 5
        -- tell application "Finder" to restart
        log "Restarting..."
    end if
    
    Note: Remove the log statements!
    Info: https://developer.apple.com/library...AutomationScriptingGuide/DisplayProgress.html
     

Share This Page