module CookieDough

Constants

BASEAPPS

a list of default apps installed by the base macOS 10.12 system

CURRENTUSER
VERSION

Public Class Methods

all_app_versions() click to toggle source

list of apps and version numbers

# File lib/cookiedough.rb, line 40
def self.all_app_versions
    apps_to_check = []
    app_versions = []

    Dir.entries("/Applications").each do |appname|
        if appname.end_with?(".app")
            apps_to_check.push(appname)
        end
    end

    for app in apps_to_check
        if File.file?("/Applications/#{app}/Contents/Info.plist")
            begin
                plist = CFPropertyList::List.new(:file => "/Applications/#{app}/Contents/Info.plist")
                results=CFPropertyList.native_types(plist.value)
            rescue
               puts "Error: misformed XML for '#{app}'"
            else
                app_versions.push("#{app} = #{results['CFBundleShortVersionString']}")
            end
        end
    end
    check=[]
    Dir.entries("/Applications").each do |appname|
        if File.directory?("/Applications/#{appname}")
            if !appname.end_with?(".app")
                if !appname.start_with?(".")
                    check.push(appname)
                end
            end
        end
    end
    check.delete("Utilities")

    direcotries=[]
    check.each do |appname|
        Dir.entries("/Applications/#{appname}").each do |app|
            if app.end_with?(".app")
                if File.exist?("/Applications/#{appname}/#{app}/Contents/Info.plist")
                    begin
                        plist = CFPropertyList::List.new(:file => "/Applications/#{appname}/#{app}/Contents/Info.plist")
                        results=CFPropertyList.native_types(plist.value)
                    rescue
                       puts "Error: misformed XML for '#{appname}/#{app}'"
                    else
                        app_versions.push("#{appname}/#{app} = #{results['CFBundleShortVersionString']}")
                    end
                end

            end
        end
    end
    return app_versions.sort
end
app_version(appname) click to toggle source

list a single app version but suppling a pathname to an app

# File lib/cookiedough.rb, line 96
def self.app_version(appname)
    if File.exist?("/Applications/#{appname}")
        if File.exist?("/Applications/#{appname}/Contents/Info.plist")
            plist = CFPropertyList::List.new(:file => "/Applications/#{appname}/Contents/Info.plist")
            results=CFPropertyList.native_types(plist.value)
            return results["CFBundleShortVersionString"]
        end
    else
        return "Error: Appliction can't be found"
    end
end
dock_apps(user = CURRENTUSER) click to toggle source

list the aspps in a users dock

# File lib/cookiedough.rb, line 109
def self.dock_apps(user = CURRENTUSER)

    plist = CFPropertyList::List.new(:file => "/Users/#{user}/Library/Preferences/com.apple.dock.plist")
    results=CFPropertyList.native_types(plist.value)
    apps=[]
    for key, value in results['persistent-apps']
        for key, value in key
            if value.class == Hash
                for x, y in value
                    if x == "file-label"
                        apps.push(y)
                    end
                end
            end
        end
    end
    return apps
end
dock_bundles(user = CURRENTUSER) click to toggle source

list the apps bundle ids in the users dock

# File lib/cookiedough.rb, line 129
def self.dock_bundles(user = CURRENTUSER)
    plist = CFPropertyList::List.new(:file => "/Users/#{user}/Library/Preferences/com.apple.dock.plist")
    results=CFPropertyList.native_types(plist.value)
    apps=[]
    for key, value in results['persistent-apps']
        for key, value in key
            if value.class == Hash
                for x, y in value
                    if x == "bundle-identifier"
                        apps.push(y)
                    end
                end
            end
        end
    end
    return apps
end
list_apps() click to toggle source

list entries in /Applications folder

# File lib/cookiedough.rb, line 18
def self.list_apps
    apps = []
    Dir.entries("/Applications").each do |appname|
        if !appname.start_with?(".")
            apps.push(appname)
        end
    end
    return apps
end
options() click to toggle source

list options

# File lib/cookiedough.rb, line 153
def self.options
    return CookieDough.methods(false).sort
end
receipts() click to toggle source

list the receipts for apps that were installed

# File lib/cookiedough.rb, line 148
def self.receipts
    results=`pkgutil --pkgs`.lines
end
user_installed_apps() click to toggle source

returns a list of apps installed by users … minus the baseapps

# File lib/cookiedough.rb, line 29
def self.user_installed_apps
    user_installed = []
    for x in list_apps
        if !CookieDough::BASEAPPS.include?(x)
            user_installed.push(x)
        end
    end
    return user_installed
end