AppleScript Library

Time Machine Library

   Some handlers to get information on Mac OS X's built in Time Machine and trigger a Time Machine backup.

All handlers displayed on this page were freely available on the internet or written by myself. Please refer to the copyright section at the end of this page. Feedback appreciated.


AppleScript Editor open download

Properties
myName
Time Machine
triggerTM
lastTMbu
oldestTMbu
getTMlog

Properties

property myName

Name that should be used when loading this library.

show source AppleScript-Editor open insert append toc
property myName : "_timemachine"

Time Machine

triggerTM()

Trigger Time Machine backup.

nothing

Written by:ljr

Example:

triggerTM() 
--> nothing (TM backup starts)
show source AppleScript Editor open insert append toc
on triggerTM()
	try
		do shell script ¬
			("/System/Library/CoreServices/backupd.bundle/" & ¬
				"Contents/Resources/backupd-helper > /dev/null 2>&1  &")
	on error eMsg number eNum
		error "Can't triggerTM: " & eMsg number eNum
	end try
end triggerTM

lastTMbu()

Get the date of the last successful Time Machine backup.

date : date of last complete BU

Man pages:  defaults

Written by:ljr

Example:

lastTMbu() 
--> date "Sonntag, 17. August 2008 8:00:20 Uhr"
show source AppleScript Editor open insert append toc
on lastTMbu()
	local lastBU, theDate
	try
		set lastBU to do shell script ¬
			"defaults read /var/db/.TimeMachine.Results " & ¬
			"BACKUP_COMPLETED_DATE"
		set theDate to (current date)
		set theDate's day to 1
		set theDate's year to ((lastBU's text 1 thru 4) as integer)
		set theDate's month to ((lastBU's text 6 thru 7) as integer)
		set theDate's day to ((lastBU's text 9 thru 10) as integer)
		set theDate's hours to ((lastBU's text 12 thru 13) as integer)
		set theDate's minutes to ((lastBU's text 15 thru 16) as integer)
		set theDate's seconds to ((lastBU's text 18 thru 19) as integer)
		return theDate
	on error eMsg number eNum
		error "Can't lastTMbu: " & eMsg number eNum
	end try
end lastTMbu

oldestTMbu()

Get the date of the oldest successful Time Machine backup available.

date : date of oldest complete BU

Man pages:  defaults

Written by:ljr

Example:

oldestTMbu() 
--> date "Freitag, 28. März 2008 18:52:10 Uhr"
show source AppleScript Editor open insert append toc
on oldestTMbu()
	local oldestBU, theDate
	try
		set oldestBU to do shell script ¬
			"defaults read /var/db/.TimeMachine.Results " & ¬
			"kCSBackupdOldestCompleteSnapshotDate"
		set theDate to (current date)
		set theDate's day to 1
		set theDate's year to ((oldestBU's text 1 thru 4) as integer)
		set theDate's month to ((oldestBU's text 6 thru 7) as integer)
		set theDate's day to ((oldestBU's text 9 thru 10) as integer)
		set theDate's hours to ((oldestBU's text 12 thru 13) as integer)
		set theDate's minutes to ((oldestBU's text 15 thru 16) as integer)
		set theDate's seconds to ((oldestBU's text 18 thru 19) as integer)
		return theDate
	on error eMsg number eNum
		error "Can't oldestTMbu: " & eMsg number eNum
	end try
end oldestTMbu

getTMlog()

Read time machine log.

text : log entries

Man pages:  syslog

Written by:ljr

Example:

getTMlog() 
--> "Thu Jan 20 22:00:14 Starting standard backup..."
show source AppleScript Editor open insert append toc
on getTMlog()
	try
		return do shell script ¬
			"syslog -F '$Time $Message' -k Sender com.apple.backupd"
	on error eMsg number eNum
		error "Can't getTMlog: " & eMsg number eNum
	end try
end getTMlog

Copyright

© 2008 ljr (http://applescript.bratis-lover.net)
triggerTM, lastTMbu, oldestTMbu, getTMlog

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.