SHARE
TWEET

Critical Updates Legacy Script

applehelpwriter Nov 1st, 2017 210 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #######################
  2. -->> ABOUT
  3. #######################
  4. (*
  5.  
  6.  Phil Stokes -- 2017
  7.  applehelpwriter.com
  8.  sqwarq.com
  9.  
  10. *)
  11. #######################
  12. -->> DESCRIPTION
  13. #######################
  14. (*
  15.  
  16. View version and modification times of background system and security updates provided by Apple.
  17.  
  18. *)
  19. #######################
  20. -->> USAGE
  21. #######################
  22. (*
  23.  
  24. The script should return usable results on 10.9 and later.
  25. Behaviour on earlier systems is undocumented.
  26.  
  27.  
  28. *)
  29. ##########################################
  30. # Variables
  31. ##########################################
  32. set updateMarker to " *"
  33.  
  34. set saveLocation to "~/Library/Preferences/com.appleseedCriticalUpdates.txt"
  35.  
  36. set lastUpdate to {}
  37.  
  38. set thisDate to {}
  39.  
  40. set hasBeenUpdated to ""
  41.  
  42. set TimeStrings to {"/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/XProtect.meta.plist", "/private/var/db/gkopaque.bundle/Contents/version.plist", "/System/Library/Sandbox/Compatibility.bundle/Contents/version.plist", "/System/Library/CoreServices/MRT.app/Contents/version.plist", "'/System/Library/Intelligent Suggestions/Assets.suggestionsassets/Contents/version.plist'", "/System/Library/Extensions/AppleKextExcludeList.kext/Contents/version.plist", "/usr/share/mecabra/updates/com.apple.inputmethod.SCIM.bundle/Contents/version.plist", "/usr/share/kdrl.bundle/info.plist"}
  43.  
  44. set VersionStrings to {"/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/XProtect.meta.plist Version", "/private/var/db/gkopaque.bundle/Contents/version.plist CFBundleShortVersionString", "/System/Library/Sandbox/Compatibility.bundle/Contents/version.plist CFBundleShortVersionString", "/System/Library/CoreServices/MRT.app/Contents/version CFBundleShortVersionString", "/System/Library/Intelligent\\ Suggestions/Assets.suggestionsassets/Contents/version.plist CFBundleShortVersionString", "/System/Library/Extensions/AppleKextExcludeList.kext/Contents/version CFBundleShortVersionString", "/usr/share/mecabra/updates/com.apple.inputmethod.SCIM.bundle/Contents/info SUVersionString", "/usr/share/kdrl.bundle/info CFBundleVersion"}
  45.  
  46. set theComponents to {(localized string "XProtect"), (localized string "Gatekeeper"), (localized string "SIP"), (localized string "Malware Removal Tool"), (localized string "Core Suggestions"), (localized string "Incompatible Kexts"), (localized string "Chinese Word List"), (localized string "Core LSKD (kdrl)")}
  47. set theTabSpaces to ""
  48.  
  49. --set _multiTabs to tab & tab & tab & tab
  50. set _multiTabs to getTabs(localized string "Component" & tab)
  51. set displayString to (localized string "Component") & _multiTabs & (localized string "Version") & tab & (localized string "Updated") & tab & tab & (localized string "Time") & return & "_________________________________________________" & return & return
  52.  
  53.  
  54. ##########################################
  55. # Handlers
  56. ##########################################
  57.  
  58.  
  59. # calculate the number of tabs required for the display dialog
  60. on getTabs(aWord)
  61.     if aWord contains "Kexts" then
  62.         return tab
  63.     else
  64.         set n to round (20 - (length of aWord)) / 4
  65.         if n is less than 0 then set n to 1
  66.         if length of aWord is 10 then set n to 2
  67.         set this_tab to tab
  68.         repeat n times
  69.             set this_tab to this_tab & tab
  70.         end repeat
  71.         return this_tab
  72.     end if
  73. end getTabs
  74.  
  75. #get the last change date
  76. on getUpdatedDate(aFile)
  77.     set d to do shell script "stat -f \"%Sc\" -t \"%m/%d/%Y %H:%M\" " & aFile
  78.     set end of my thisDate to d
  79.     return d
  80.    
  81. end getUpdatedDate
  82.  
  83. #compare the dates to see if there's been a change
  84. on checkLastUpdate(aDateString, anIndex)
  85.     set n to text 1 thru 10 of aDateString
  86.     set o to text 1 thru 10 of my (item anIndex of lastUpdate)
  87.    
  88.     if (n is equal to o) then
  89.         return ""
  90.     else
  91.         return my updateMarker
  92.     end if
  93. end checkLastUpdate
  94.  
  95.  
  96. ##########################################
  97. # Commands
  98. ##########################################
  99.  
  100. # read the dates into our script from the last run
  101. set oldTIDS to AppleScript's text item delimiters
  102. set AppleScript's text item delimiters to ","
  103. try
  104.     set s to (do shell script "cat " & saveLocation)
  105.     set lastUpdate to text items of s
  106. end try
  107. set AppleScript's text item delimiters to oldTIDS
  108.  
  109. # this is the workhorse, getting all the data for each component
  110. repeat with i from 1 to number of items in theComponents
  111.     try
  112.         set component_item to item i of theComponents
  113.         set version_item to item i of VersionStrings
  114.         set time_item to item i of TimeStrings
  115.         set theTabSpaces to getTabs(component_item)
  116.         set updatedDate to getUpdatedDate(time_item)
  117.        
  118.         # check if we had some saved dates from a previous run
  119.         #and if so, check them against the current dates
  120.         if (count of (lastUpdate as list)) = (count of theComponents) then
  121.             set my hasBeenUpdated to checkLastUpdate(updatedDate, i)
  122.         end if
  123.        
  124.         # organise the display string
  125.         set v to (do shell script "defaults read " & version_item)
  126.         if component_item contains "Kexts" and (text 1 of v is "1") then
  127.             set v to v
  128.         else if length of v < 4 or (length of v < 6 and v contains ".") then
  129.             set v to v & tab
  130.         end if
  131.         set displayString to displayString & component_item & theTabSpaces & v & tab & updatedDate & my hasBeenUpdated & return
  132.         set my hasBeenUpdated to ""
  133.     end try
  134. end repeat
  135.  
  136. #write out current dates to file
  137. set writeData to ""
  138. repeat with i from 1 to number of items in thisDate
  139.     set this_item to item i of thisDate
  140.     if length of writeData is 0 then
  141.         set writeData to this_item
  142.     else
  143.         set writeData to writeData & "," & this_item
  144.     end if
  145. end repeat
  146. do shell script "echo " & writeData & "> " & saveLocation
  147.  
  148. # finally, get the OS version and build
  149. set theSysInfo to (do shell script "sw_vers")
  150. set sysString to paragraph 2 of theSysInfo & return & paragraph 3 of theSysInfo
  151. set displayString to displayString & return & sysString
  152.  
  153. # and...
  154. set _close to localized string "Close"
  155. set _title to localized string "Critical Updates (Legacy Vers 1.3.3)"
  156. display dialog displayString buttons {_close} default button _close with title _title
  157.  
  158. #EOF
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top