Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Compton

macrumors member
Original poster
Sep 8, 2010
42
0
I back up my macbook on two different drives almost daily, one at my work place and one at home. I would like to automate this using applescript and I already found the code that does almost exactly what I want. The code is

property pth : "Macintosh HD:Library:preferences:"
property d1name : "Backup Disk 1"
property d1 : "com.apple.TimeMachine.Disk1.plist"
property d2name : "Backup Disk 2"
property d2 : "com.apple.TimeMachine.Disk2.plist"
property active : "com.apple.TimeMachine.plist"

do shell script "defaults write com.apple.TimeMachine AutoBackup -bool false"

if (list disks) contains d1name then
tell application "Finder" to if exists (pth & d1) then
set name of file (pth & active) to d2
set name of file (pth & d1) to active
end if
else if (list disks) contains d2name then
tell application "Finder" to if exists (pth & d2) then
set name of file (pth & active) to d1
set name of file (pth & d2) to active
end if
end if

do shell script "defaults write com.apple.TimeMachine AutoBackup -bool true"


The only problem is that Finder asks for my administrator password twice during the script to rename the plist files in the system folder. I tried changing the "sharing and permissions" option for these particular files through the "Get info" dialog to to enable read/write but this didn't appear to have any effect.

How should the script be modified so that it would rename the plist files but not ask for system password? Thanks in advance.
 
Renaming is not an operation on a file, but an operation on the folder that contains a name to the file. You could try changing the permissions of the /Library/Preferences folder, but I find that unsettling.
 
Renaming is not an operation on a file, but an operation on the folder that contains a name to the file. You could try changing the permissions of the /Library/Preferences folder, but I find that unsettling.

Changing the permissions of the entire Preferences folder did work, thanks for the tip! I also find this solution a bit unsettling so I would be interested in hearing other options. I have read something about enabling read/write access for specific files through shell scripts. Perhaps someone could provide me with the appropriate shell script if this is the case.

Edit: deleted an unnecessary question.
 
Last edited:
Perhaps someone could provide me with the appropriate shell script if this is the case.

As it's hierarchical you'd need write permissions to the folder before the file.

An alternative is to run the script as a launch daemon so it runs as root.
 
As it's hierarchical you'd need write permissions to the folder before the file.

An alternative is to run the script as a launch daemon so it runs as root.

Could you provide an example? I'm not familiar with shell scripts or launch daemons so it would take me a while to figure out what you're saying.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.