Johan de Klerk
Johan de Klerk

Reputation: 2535

Delete Apps from iOS Simulator using terminal

Im trying to delete apps from the iOS Simulator using this script running on our Build Server

#!/bin/Bash

#Go to iOS Sim
cd ~/Library/Application\ Support/iPhone\ Simulator

#Loop through each Version of iOS
for dir in ~/Library/Application\ Support/iPhone\ Simulator/*/
do
    dir=${dir%*/}
    cd "$dir"

    #Check if the iOS version has any apps installed                    
    if [ -d "$dir/Applications" ]; then
        echo Applications folder exists in "$dir"
        cd "$dir/Applications"

        #Delete each app
        for app in "$dir/Application/*/"
        do
            echo $app

            if [ "${#app}" -eq 36 ]; then   
                echo Delete Folder
            fi
        done

    fi
done

Im stuck at the #Delete each app section. I want to loop through the Applications folder and first check if the Folder's number of characters is 36(GUID) then delete the folder

Upvotes: 0

Views: 557

Answers (2)

user000001
user000001

Reputation: 33367

If you have a * in quotes, bash will interpret it literally, and not as a glob. You could change the for to this:

 for app in "$dir"/Application/*/

Of course you have already entered the directory, so

for app in */

is probably what you want to do

Upvotes: 1

user1898811
user1898811

Reputation:

I'm all about using the numerous (and awesome) utilities you have at hand for this sort of thing. You can use something like

LENGTH=`echo $app | wc -c`
if [[ $LENGTH -eq 36 ]]; then
  # do the thing
fi

Note: The magic here is the use of back ticks and the wc (wordcount) utility. While you're looking at the man page for wc, checkout tr also (only partially related, but another excellent tool to knw).

Upvotes: 0

Related Questions