Reference Mac App Store download directory in script

agetz
Contributor

I am trying to do something rather interesting to help our student body with Garageband. These are non-admin accounts, installing Garageband from VPP in Self Service.

I have other scripts to automatically download and install this content but for those that have already spent the time downloading the essential content or the complete sound library I want to have a script that will find their Garageband download directory, reference its location and run the pkgs within it. I have another script that can run the installers if I know the directory location, the trick is that these folder names are generated randomly and stored in the /var/folders/ structure which makes it tricky to search for.

Any help is greatly appreciated.

1 ACCEPTED SOLUTION

mm2270
Legendary Contributor II

Ok, makes sense.

So, one other question. Is that "lp10_ms3_content_2016" folder always the same when the GarageBand content is downloaded? The reason the script I posted is not working is because in this special instance, the folder it creates is not the application ID from the Mac App Store, as we can see. IF, and it's a big IF that you will need to test out, that folder is always named that way when GB content is downloaded, then replace the "682658836" in the script with "lp10_ms3_content_2016" and see if it then works. IOW, have the script look for that folder and then determine if PKGs are inside it to install.

That's the best I can offer since I don't have a system ready I can do actual testing with. Hopefully that dir is always named that way, and hopefully that will address it for you.

View solution in original post

10 REPLIES 10

mm2270
Legendary Contributor II

So, is the software download you're trying to reference something that can be found directly in the Mac App Store? Do you know if it has a Mac App Store application ID number? Generally speaking, all apps that show up in the MAS (to my knowledge anyway) have an application ID, which is usually a string of 9 or 10 numbers.
If you're not sure what that ID is, you can try downloading and installing it on a Mac and use the mas command line tool, found here to get the ID number. With that installed, you would then run something like:

mas list

and look for the specific product name. To the left of that will be its application ID string.

Believe it or not, those folders in /private/var/folders/vb/ are not quite as random as you may think. The enclosing folder may be named randomly, but usually the rest of it follows a pattern. I don't know for sure, but on mine, after /private/var/folders/vb/ I see a randomly named folder and then folders like "C" and "T" For me at least, the downloads go into that "C" directory, and then into "com.apple.appstore"

If I know the application ID of the app, I can then use that to locate the folder it downloads to, since it matches that ID. In fact, you could actually locate it with a simple find command. For example, say the product ID you're looking for is something like "715768417" In this case, that's the ID for Microsoft Remote Desktop. I can run the following to locate the directory an update for it is downloaded to:

find /private/var/folders/vb -name 715768417 -type d

This, for me, returns

/private/var/folders/vb/gb44pvwd2kxcq3ln0b79j_s1ddxchk/C/com.apple.appstore/715768417

I can store that as a variable to use to search for .pkg files inside it.

Here's an example of how to pull this all together. The below is untested, but try it out to see if it helps.

#!/bin/sh

## Put the MAS application ID in the variable below (Example below is for Microsoft Remote Desktop)
productID="715768417"

## This locates the download directory, if present
downloadDir=$(find /private/var/folders/vb -name $productID -type d)

## If there is a download dir, search for pkgs within it
if [ ! -z "$downloadDir" ]; then
    pkgInstaller=$(find "$downloadDir" -name *.pkg)

    if [ ! -z "$pkgInstaller" ]; then
        ## Get the qty of pkgs found
        pkgCount=$(echo "$pkgInstaller" | awk END'{print NR}')
        ## If only one pkg, install it
        if [[ $pkgCount == 1 ]]; then
            echo "One package install located. Installing..."
            /usr/sbin/installer -pkg "$pkgInstaller" -tgt /
        elif [[ $pkgCount -gt 1 ]]; then
            ## If more than one pkg found, install them all
            echo "More than one package is in this directory. Looping..."
            while read PKG; do
                /usr/sbin/installer -pkg "$PKG" -tgt /
            done < <(echo "$pkgInstaller")
        fi
    else
        echo "No packages located within the download directory. Exiting..."
        exit 0
    fi
else
    echo "No download directory for the application ID was found. Exiting..."
    exit 0
fi

agetz
Contributor

Thanks for the reply, @mm2270 . I am having an issue getting that script to run. I found the id through the app store link and replaced the value. I also replaced the sub folder of folders with an accurate one from my test computer.

find /private/var/folders/td -name 682658836 -type d

This command is not returning anything.

mm2270
Legendary Contributor II

@agetz So is it actually "td" on your test Mac? I guess that directory is random then, because on mine it's "vb"

Question - can you navigate to that /private/var/folders/td/ directory and see if there is an "com.apple.appstore" folder there? If there is, is there then a "682658836" within it?

agetz
Contributor

@mm2270 Within the td folder, there is then a long 'random' value and some other subs

This is the actual directory path the the pks I need to reference.

dm1r8xxxxxxxxxxxxxxxxx Ccom.apple.MusicAppsaudiocontentdownload.apple.comlp10_ms3_content_2016

There is a com.apple.appstore in the C directory but no mention of an ID number in it.

mm2270
Legendary Contributor II

Ok, that helps a little. So it looks like the GarageBand content then gets downloaded into something different than regular App Store downloads. Which maybe explains why the script isn't working. So inside that last "lp10_ms3_content_2016" folder, do you see actual .pkg installers? Or more sub-folders?
It's possible for these types of additional content downloads it's not going to be possible to script installing them. I'm not really sure, as I haven't downloaded those files and tried to then access them after.

Truthfully, I'm wondering why any of this is actually necessary anyway. Why is it the end users can't install these themselves? if they are getting downloaded from the App Store isn't it just installing them afterwards? Maybe I'm just not fully understanding the core issue. I was under the impression standard user accounts could use the App Store to install stuff, no?

agetz
Contributor

@mm2270 Garageband is different in that regard. You must have admin right to install the add-on instruments that are downloaded within the app. You are right that normally standard accounts can install App Store apps just fine.

The pkgs are listed in that directory.

mm2270
Legendary Contributor II

Ok, makes sense.

So, one other question. Is that "lp10_ms3_content_2016" folder always the same when the GarageBand content is downloaded? The reason the script I posted is not working is because in this special instance, the folder it creates is not the application ID from the Mac App Store, as we can see. IF, and it's a big IF that you will need to test out, that folder is always named that way when GB content is downloaded, then replace the "682658836" in the script with "lp10_ms3_content_2016" and see if it then works. IOW, have the script look for that folder and then determine if PKGs are inside it to install.

That's the best I can offer since I don't have a system ready I can do actual testing with. Hopefully that dir is always named that way, and hopefully that will address it for you.

agetz
Contributor

@mm2270 You have earned a beer my friend. This will help me finish out the script Im working on that will allow standard users to install Garageband Instruments. Will post here after I've finished it. I found that values within the 'folders' folder are random and are made for each user account on the computer. Removing that gave me the value I was after even with different user accounts. As long as the download has been initiated in the app, the folder "lp10_ms3_content_2016" is created and able to be referenced. Thanks again.

!/bin/sh

productID="lp10_ms3_content_2016"

This locates the download directory, if present

downloadDir=$(find /private/var/folders -name $productID -type d)

echo "$downloadDir"

StoneMagnet
Contributor III

@agetz If you lead and end your code snippet with three consecutive backtick characters "`" you can paste a script without getting the formatting mangled

agetz
Contributor
#!/bin/bash
# Aaron Getz
# Jacob Salmela
# Bash version of https://github.com/erikng/adminscripts/blob/master/download-gb-content.py
# Find feature from mm2270
downloadFolder=$(find /private/var/folders -name lp10_ms3_content_2016 -type d)

# Put all the package names into an array, include all that may exist in the folder, can make separate scripts for different packs
# https://jamfnation.jamfsoftware.com/discussion.html?id=14594#responseChild93147
# http://www.amsys.co.uk/2015/blog/download-garageband-logic-pro-x-content-loops-deployment/
content=('MAContent10_AssetPack_0161_AlchemyGuitarsElectricPadScratching.pkg'
'MAContent10_AssetPack_0337_IRsLargeSpacesIndoor.pkg'
'MAContent10_AssetPack_0339_IRsLargeSpacesWarped.pkg')

# Loop through each one and install it
echo "** Installing Content..."
for ((i = 0; i < "${#content[@]}"; i++))
do
    echo "Installing ${content[$i]}..."
    installer -pkg "$downloadFolder"/"${content[$i]}" -target /
done