Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

10.5: Run a Time Machine backup then shut down System 10.5
Here's an AppleScript I use to run a Time Machine backup, and then shut down the machine. As is the case with most shut down scripts, I suppose it would be a good idea to quit whatever programs you know of that are open before running the script. [robg adds: I haven't tested this one, beyond making sure it compiled in Script Editor. After pasting into Script Editor, save it as a script then use your favorite method of making it easier to access -- toolbar, sidebar, dock, or hot keys via a third-party app.]
    •    
  • Currently 2.67 / 5
  You rated: 4 / 5 (9 votes cast)
 
[20,062 views]  

10.5: Run a Time Machine backup then shut down | 5 comments | Create New Account
Click here to return to the '10.5: Run a Time Machine backup then shut down' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Run a Time Machine backup then shut down
Authored by: lukec on Jun 27, '08 08:52:03AM
It's a good point to quit open programs before running this script. Open applications could prevent data from being backed up and could stall the shutdown.

You could accomplish that and have the script run using a logout script:
http://www.bombich.com/mactips/loginhooks.html

When you call shutdown, your user would log out, which would quit the open applications and call the script and then shutdown. (remove shutdown from the script)

This might not work if backupd-helper is dependent on having a user log in, but as the launchctl files are in the system area, the services start independent of a user login and so that shouldn't be an issue.

Luke

[ # ]
10.5: Run a Time Machine backup then shut down
Authored by: wallybear on Jun 27, '08 09:08:50AM
Your script can be trimmed a lot:

property querylist : {"backupd"}
property app_is_up : missing value --this line is superfluous

set app_is_up to false

do shell script
"/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper > /dev/null 2>&1  &"

repeat
	delay 10
	repeat with i in querylist
		if IsProcRunning(i) then set app_is_up to true
	end repeat
	if app_is_up then
		set app_is_up to false
	else
		ignoring application responses
			tell application "loginwindow" to «event aevtshut»
		end ignoring
		exit repeat
	end if
end repeat

on IsProcRunning(theProc)
	try
		do shell script "ps auxc | grep \"" & theProc & "\""
		return true
	on error
		return false
	end try
end IsProcRunning


and, as you look only for the "backupd" process, can be trimmed down to this:


do shell script
"/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper > /dev/null 2>&1  &"

repeat
	delay 10
	if not IsProcRunning("backupd") then
		ignoring application responses
			tell application "loginwindow" to «event aevtshut»
		end ignoring
		exit repeat
	end if
end repeat

on IsProcRunning(theProc)
	try
		do shell script "ps auxc | grep \"" & theProc & "\""
		return true
	on error
		return false
	end try
end IsProcRunning


Moreover, it would be better making it a logout script

[ # ]
10.5: Run a Time Machine backup then shut down
Authored by: RecordingArts on Jun 27, '08 09:47:35AM

Is there a script that would simply unmount the time machine volume after backup is complete? If not, would you please consider writing one?

My parents are older, and I've got them to attach the time machine volume to their MacBook, but I think they usually unhook it without unmounting it first.



[ # ]
10.5: Run a Time Machine backup then shut down
Authored by: wallybear on Jun 27, '08 02:53:43PM
It's fairly simple: in the script, just replace the lines

	ignoring application responses
		tell application "loginwindow" to «event aevtshut»
	end ignoring
with this single line

	tell application "Finder" to eject disk "YourTimeMachineVolume"
(obviously replace YourTimeMachineVolume with the real name of your Time Machine disk)
Moreover, if you want the script not to launch the backup (because you prefer to launch it by TM menu) but only unmount the volume when Time Machine has finished, remove the following line from the script:

   do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper > /dev/null 2>&1  &"


[ # ]
10.5: Run a Time Machine backup then shut down
Authored by: aquraishi on Jul 04, '08 09:40:43AM

This is an interesting solution but will it backup encrypted volumes? My understanding is that if your home folder is encrypted the time machine backup will only work (for that folder) when you're logged out.



[ # ]