This is a script I wrote a few years ago to read the output as a dictionary and to write the information “BackupPhase”, “Running”, “Stopping” and “Percent” into a txt file. The handler isBackupRunning() returns true if a backup is currently running
It might be a starting point
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions
property |⌘| : a reference to current application
on isBackupRunning()
global tmStatus
set text item delimiters to {""}
set tmutilStatus to |⌘|'s NSString's stringWithString:(paragraphs 2 thru -1 of (do shell script "tmutil status") as text)
set plistData to tmutilStatus's dataUsingEncoding:(|⌘|'s NSUTF8StringEncoding)
set {tmStatus, tmError} to |⌘|'s NSPropertyListSerialization's propertyListWithData:plistData options:0 format:(|⌘|'s NSPropertyListOpenStepFormat) |error|:(reference)
set phase to "n/a"
set isStopping to "n/a"
set isRunning to "n/a"
set percent to "n/a"
set bPh to tmStatus's objectForKey:"BackupPhase"
if bPh is not missing value then set phase to bPh as text
set isR to tmStatus's objectForKey:"Running"
if isR is not missing value then set isRunning to isR as text
set isS to tmStatus's objectForKey:"Stopping"
if isS is not missing value then set isStopping to isS as text
set perc to tmStatus's objectForKey:"Percent"
if perc is not missing value then set percent to perc as text
writeToDisk(phase, isRunning, isStopping, percent)
return tmError is missing value and (tmStatus as record)'s |running|() = "1"
end isBackupRunning
isBackupRunning()
on writeToDisk(phase, isR, isS, percent)
set theFile to (path to desktop as text) & "tmstatus.txt"
try
set fileDescriptor to open for access theFile with write permission
set theLine to "Phase: " & phase & " - isRunning: " & isR & " - isStopping: " & isS & " - Percent: " & percent & return
write theLine to fileDescriptor as «class utf8» starting at eof
close access fileDescriptor
return true
on error e
e
try
close access theFile
end try
return false
end try
end writeToDisk