#start
##########################################
# Variables
##########################################
set updateMarker to " *"
# note that this script will write to this location when it’s done
set saveLocation to "~/Library/Preferences/com.appleBackgroundUpdates.CriticalUpdates.txt"
set lastUpdate to {}
set thisDate to {}
set hasBeenUpdated to ""
set TimeStrings to {"/System/Library/CoreServices/XProtect.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"}
set VersionStrings to {"/System/Library/CoreServices/XProtect.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"}
set theComponents to {(localized string "XProtect"), (localized string "Gatekeeper"), (localized string "System Integrity Protect..."), (localized string "Malware Removal Tool"), (localized string "Core Suggestions"), (localized string "Incompatible Kernel Ext..."), (localized string "Chinese Word List"), (localized string "Core LSKD (kdrl)")}
set theTabSpaces to ""
--set _multiTabs to tab & tab & tab & tab
set _multiTabs to getTabs(localized string "Component" & tab)
set displayString to (localized string "Component") & _multiTabs & (localized string "Version") & tab & (localized string "Updated") & tab & tab & (localized string "Time") & return & "_______________________________________________________________" & return & return
##########################################
# Handlers
##########################################
# calculate the number of tabs required for the display dialog
on getTabs(aWord)
set n to round (25 - (length of aWord)) / 4
if n is less than 0 then set n to 1
if length of aWord is 10 then set n to 3
set this_tab to tab
repeat n times
set this_tab to this_tab & tab
end repeat
return this_tab
end getTabs
#get the last change date
on getUpdatedDate(aFile)
set d to do shell script "stat -f \"%Sc\" -t \"%d-%m-%Y %H:%M\" " & aFile
set end of my thisDate to d
return d
end getUpdatedDate
#compare the dates to see if there's been a change
on checkLastUpdate(aDateString, anIndex)
set n to text 1 thru 10 of aDateString
set o to text 1 thru 10 of my (item anIndex of lastUpdate)
if (n is equal to o) then
return ""
else
return my updateMarker
end if
end checkLastUpdate
##########################################
# Commands
##########################################
# read the dates into our script from the last run
set oldTIDS to AppleScript's text item delimiters
set AppleScript's text item delimiters to ","
try
set s to (do shell script "cat " & saveLocation)
set lastUpdate to text items of s
end try
set AppleScript's text item delimiters to oldTIDS
# this is the workhorse, getting all the data for each component
repeat with i from 1 to number of items in theComponents
try
set component_item to item i of theComponents
set version_item to item i of VersionStrings
set time_item to item i of TimeStrings
set theTabSpaces to getTabs(component_item)
set updatedDate to getUpdatedDate(time_item)
# check if we had some saved dates from a previous run
#and if so, check them against the current dates
if (count of (lastUpdate as list)) = (count of theComponents) then
set my hasBeenUpdated to checkLastUpdate(updatedDate, i)
end if
# organise the display string
set v to (do shell script "defaults read " & version_item)
if length of v < 4 or (length of v < 6 and v contains ".") then set v to v & tab
set displayString to displayString & component_item & theTabSpaces & v & tab & updatedDate & my hasBeenUpdated & return
set my hasBeenUpdated to ""
end try
end repeat
#write out current dates to file
set writeData to ""
repeat with i from 1 to number of items in thisDate
set this_item to item i of thisDate
if length of writeData is 0 then
set writeData to this_item
else
set writeData to writeData & "," & this_item
end if
end repeat
do shell script "echo " & writeData & "> " & saveLocation
# finally, get the OS version and build
set theSysInfo to (do shell script "sw_vers")
set sysString to paragraph 2 of theSysInfo & return & paragraph 3 of theSysInfo
set displayString to displayString & return & sysString
# and...
set _close to localized string "Close"
set _title to localized string "Critical Updates (v.1.3)"
display dialog displayString buttons {_close} default button _close with title _title
#EOF