Module: CookieDough
- Defined in:
- lib/cookiedough.rb,
lib/cookiedough/version.rb
Constant Summary collapse
- CURRENTUSER =
Etc.getlogin
- BASEAPPS =
a list of default apps installed by the base macOS 10.12 system
[ "App Store.app", "Automator.app", "Calculator.app","Calendar.app", "Chess.app", "Contacts.app", "Dashboard.app", "Dictionary.app", "DVD Player.app", "FaceTime.app", "Font Book.app", "Game Center.app", "iBooks.app", "Image Capture.app","iTunes.app", "Launchpad.app", "Mail.app", "Maps.app", "Messages.app", "Mission Control.app", "Notes.app", "Photo Booth.app", "Photos.app", "Preview.app", "QuickTime Player.app", "Reminders.app", "Safari.app", "Stickies.app", "System Preferences.app", "TextEdit.app", "Time Machine.app", "Utilities"]
- VERSION =
"0.1.0"
Class Method Summary collapse
-
.all_app_versions ⇒ Object
list of apps and version numbers.
-
.app_version(appname) ⇒ Object
list a single app version but suppling a pathname to an app.
-
.dock_apps(user = CURRENTUSER) ⇒ Object
list the aspps in a users dock.
-
.dock_bundles(user = CURRENTUSER) ⇒ Object
list the apps bundle ids in the users dock.
-
.list_apps ⇒ Object
list entries in /Applications folder.
-
.options ⇒ Object
list options.
-
.receipts ⇒ Object
list the receipts for apps that were installed.
-
.user_installed_apps ⇒ Object
returns a list of apps installed by users …
Class Method Details
.all_app_versions ⇒ Object
list of apps and version numbers
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/cookiedough.rb', line 39 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) ⇒ Object
list a single app version but suppling a pathname to an app
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/cookiedough.rb', line 95 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) ⇒ Object
list the aspps in a users dock
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/cookiedough.rb', line 108 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) ⇒ Object
list the apps bundle ids in the users dock
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/cookiedough.rb', line 128 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 ⇒ Object
list entries in /Applications folder
17 18 19 20 21 22 23 24 25 |
# File 'lib/cookiedough.rb', line 17 def self.list_apps apps = [] Dir.entries("/Applications").each do |appname| if !appname.start_with?(".") apps.push(appname) end end return apps end |
.options ⇒ Object
list options
152 153 154 |
# File 'lib/cookiedough.rb', line 152 def self. return CookieDough.methods(false).sort end |
.receipts ⇒ Object
list the receipts for apps that were installed
147 148 149 |
# File 'lib/cookiedough.rb', line 147 def self.receipts results=`pkgutil --pkgs`.lines end |
.user_installed_apps ⇒ Object
returns a list of apps installed by users … minus the baseapps
28 29 30 31 32 33 34 35 36 |
# File 'lib/cookiedough.rb', line 28 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 |