PDA

View Full Version : Scripts


MarkW19
03-15-2006, 05:20 PM
As I've got a seperate backup partition (as I'm sure most of us have), I don't really want this mounting on the desktop all the time.

Is there a way to do a script or something, so that when SD starts it's scheduled backup, it mounts my backup partition, does the backup, and then unmounts it afterwards (and sends my computer to sleep as normal)?

dnanian
03-15-2006, 06:09 PM
There are number of suggested scripts and the like that do that elsewhere on the forum, Mark. Have a look around and you should find something to your liking.

MarkW19
03-15-2006, 06:36 PM
Thanks Dave.

MarkW19
03-15-2006, 07:24 PM
OK, I've had a good look around, and I've played around with some scripts to get one that actually complies ok with no errors.

I thought this one would work, but it doesn't. Can anyone tell me where I've gone wrong? The partition I want to mount is called Backup, and according to Disk Utility it's disk identifier is disk0s5, so I put that into the script...

=====
-- SuperDuper! scheduled copy script template (c) 2005-2006 by Bruce Lacey. Published by Shirt Pocket.
-- Script by Dave Nanian and Bruce Lacey

on beforeRunningCopy()
tell application "Finder"
if not (exists the disk Backup) then
do shell script "diskutil mount `disktool -l | grep 'Backup' | sed 's/.*\\(disk0s5*\\).*/\\1/'`"
delay 1
end if
end tell

delay 2
end beforeRunningCopy

on afterRunningCopy()
tell application "Finder"
if (exists the disk "Backup") then
eject "Backup"
delay 2
end if
end tell

delay 2
end afterRunningCopy

dnanian
03-15-2006, 08:26 PM
Well, Mark, if you know it's disk0s5 already, and you're basically locking it down to that device ID in your expression, there's no point doing the while disktool -l bit. Instead, to see if it works, just do a mount of disk0s5:

do shell script "diskutil mount disk0s5"

MarkW19
03-16-2006, 07:28 AM
I've done diskutil mount disk0s5, and diskutil unmount disk0s5 in terminal, and both work perfectly.

However, my script doesn't appear to work (it won't mount Backup if it's not already mounted):-

on beforeRunningCopy()
tell application "Finder"
if not (exists the disk Backup) then
do shell script "diskutil mount disk0s5"
delay 1
end if
end tell

delay 2
end beforeRunningCopy

on afterRunningCopy()
tell application "Finder"
if (exists the disk "Backup") then
eject "Backup"
delay 2
end if
end tell

delay 2
end afterRunningCopy

What am I doing wrong?

Cuneyt
03-16-2006, 08:16 AM
beforeRunningCopy() and afterRunningCopy() are subroutines and subroutines don't run unless you tell them to run in the script.

MarkW19
03-16-2006, 08:19 AM
How do I tell them to run in the script?

Cuneyt
03-16-2006, 08:24 AM
insert a beforeRunningCopy() line where you want that subroutine to run.

dnanian
03-16-2006, 08:52 AM
I'm assuming this script is actually part of your scheduled item, and you didn't delete the rest of it (hopefully). If you did remove the rest, then Cuneyt is right: the script doesn't do anything, because there's nothing calling those routines.

MarkW19
03-16-2006, 01:16 PM
I haven't deleted the rest of it, I just pasted the relevant parts here :)

I'll give it a shot now...

dnanian
03-16-2006, 01:19 PM
That's what I thought! :)

It might be worthwhile actually running the script outside of SD! (without the SD! parts) to see what it does in a controlled environment.

MarkW19
03-16-2006, 01:25 PM
OK it still doesn't do anything, as you may have guessed I've no experience whatsoever with scripting!!

How do I modify this so it works:-

-- SuperDuper! scheduled copy script template (c) 2005-2006 by Bruce Lacey. Published by Shirt Pocket.
-- Script by Dave Nanian and Bruce Lacey

on beforeRunningCopy()
tell application "Finder"
if not (exists the disk Backup) then
do shell script "diskutil mount disk0s5"
delay 1
end if
end tell

delay 2
beforeRunningCopy()
end beforeRunningCopy

on afterRunningCopy()
tell application "Finder"
if (exists the disk "Backup") then
eject "Backup"
delay 2
end if
end tell

delay 2
afterRunningCopy()
end afterRunningCopy

MarkW19
03-16-2006, 01:26 PM
Where do I insert the "beforeRunningCopy()" and "afterRunningCopy()" to ensure they both work?

MarkW19
03-16-2006, 04:50 PM
Anybody? :P

dnanian
03-16-2006, 06:47 PM
Mark --

Try simplifying things. Open Script Editor, and then JUST put in:

do shell script "diskutil mount disk0s5"

Run that. Does it work?

MarkW19
03-17-2006, 07:30 PM
Mark --

Try simplifying things. Open Script Editor, and then JUST put in:

do shell script "diskutil mount disk0s5"

Run that. Does it work?

Yes it does :)

dnanian
03-17-2006, 07:46 PM
Well, then, it should certainly work "live". You might want to do a "display dialog" in there, or something to show that it's running. If not, are you certain that you're recompiling it by changing your schedule?

MarkW19
03-17-2006, 07:56 PM
I just did this, and again it didn't mount the disk (then superduper quits after approx 5 secs):-

-- SuperDuper! scheduled copy script template (c) 2005-2006 by Bruce Lacey. Published by Shirt Pocket.
-- Script by Dave Nanian and Bruce Lacey

on beforeRunningCopy()
do shell script "diskutil mount disk0s5"
end beforeRunningCopy

on afterRunningCopy()
do shell script "diskutil unmount disk0s5"
end afterRunningCopy

MarkW19
03-17-2006, 07:57 PM
Yes I am recompiling by editing the schedule (I know this because occasionally when I've got the syntax wrong etc. then after "editing" the schedule it says there's a script error).

dnanian
03-17-2006, 08:21 PM
Try telling Finder or System Events to do the shell script. So:

tell application "System Events" to do shell script ...

MarkW19
03-17-2006, 08:30 PM
Yes!! It's worked!!

Good work Dave :)

dnanian
03-18-2006, 01:36 AM
Yay! Finally... (whew)