Script for Hard drive

I have a problem. I own a WD Mybook mirror edition usb hard drive and when i turn computer on and work with it its normal but after 10 minutes of innactivity WD mybook goes to sleep mode. After returning to normal mode it shows all kind of hard drive errors and work is not possible until restart. I wonder if script can help me to every (x minutes) to “ping” or open folder on external USB WD mybook so it wont go into sleep mode. Thank you in advance for answers.

Model: iMac
Browser: Firefox 3.0.4
Operating System: Mac OS X (10.5)

Do you have “Put the hard disk(s) to sleep when possible” checked in the “Energy Saver” preference pane? If so, uncheck it.

Here’s a Ping script for you.

try
	do shell script "ping -c localhost"
	return display dialog "Works!"
on error
	return display dialog "cannot connect."
end try

Its unchecked. Sleep mode is a part of WD mybook Usb HD firmware and cant be turned off.

regarding script :
Here’s a Ping script for you.

Applescript:

try
   do shell script "ping -c localhost"
   return display dialog "Works!"
on error
   return display dialog "cannot connect."
end try

Wont this ping my computer network adapter (localhost) and not the external HD ?
Thank you

Yep you need to change localhost to whatever your HD is set to. i didn’t know what that was, maybe it’s an ip address… but change localhost to what it is then it should work. If not make sure you have the second display dialog say that or something to clue you that it’s not pinging.

Sorry for noob questions but how to do that ?
How to set that localhost is external hard drive ?
And how to put a timer in script to ping automatic every x minutes ?

Thanks a million

You can’t ping a locally connected resource it’s purely for checking network connectivity. If you have your external HD connected via Firewire or USB there is nothing to ping so not sure where people were headed with that.

As for running a script after every X amount of time has passed you want to look at idle handlers.

Anybody with a right direction on my problem :slight_smile: ?

Well it’s hard to say. Assuming that any sort of file system activity will keep the drive awake you could do something like this.

on idle
	try
		do shell script "touch /Volumes/External-HD-Name/.stayawake"
	end try
	return (60 * 9)
end idle

Just substitute the ‘External-HD-Name’ with the name of the disk as it appears on your desktop.

on idle
try
do shell script “touch /Volumes/External-HD-Name/.stayawake”
end try
return (60 * 9)
end idle

Is (60*9) every 9 minutes ?
Thank you

yes the 60*9 is 9 minutes.

Thank you for your help, i will try it tomorrow

Best regards

Great to hear; I hope it works for you.

I have a problem with idle handler.

on idle
try
do shell script “touch /Volumes/External-HD-Name/.stayawake”
end try
return 300
end idle

this wont execute.
If i substitute (on idle) with (on run) it works but i need idle handler because of timer.

I even tried simplest use of idle handler like:

on idle
beep
return 1
end idle

even this wont “play” :slight_smile:
What am i doing wrong ?
Thank you

When you save the script with the idle handler you need to save it as Application with the “Stay Open” option selected. Now you have an application that you have to actually launch. From there the idle handler kicks in and every 9 minutes it triggers.

You need to save the script as an application and check the ‘Stay Open’ box.

Cheers,

Craig

Sorry James,

Didn’t mean to step on your post. :slight_smile:

Craig

LOL, no problem Craig. The more the merrier :smiley:

Thank you !!!
I told you I was a noob.
It works. I will now see if my drive will go to sleep mode.

BEST REGARDS

Cheers man! Make sure you let us know how it goes, I’m interested to see if that will make the drive think it’s active.

And you’re not a noob, we were all new to AppleScript at some point!