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

Stiruam

macrumors newbie
Original poster
Jul 28, 2010
5
0
I am trying to create a script that would mount and demount my Optibay HDD in my Macbook Pro. I'll be using the (remapped) eject key for running this script.

The HDD is an encrypted HFS+ partition named HDD.

I am using the following applescript:
Code:
set myVolumeLabel to "HDD"

tell application "Finder"
	set diskDev to do shell script "diskutil list | grep \"" & myVolumeLabel & "\" | grep -o 'disk[0-9]*' "
	if not (disk myVolumeLabel exists) then
		do shell script "diskutil mountDisk " & diskDev
	else
		do shell script "diskutil eject " & diskDev
	end if
end tell

The Applescript editor gives me this output:
Code:
tell application "Finder"
	do shell script "diskutil list | grep \"HDD\" | grep -o 'disk[0-9]*' "
		[COLOR="Red"]--> error number -10004[/COLOR]
end tell
tell current application
	do shell script "diskutil list | grep \"HDD\" | grep -o 'disk[0-9]*' "
		--> "disk2"
end tell
tell application "Finder"
	exists disk "HDD"
		--> false
	do shell script "diskutil mountDisk disk2"
		[COLOR="Red"]--> error number -10004[/COLOR]
end tell
tell current application
	do shell script "diskutil mountDisk disk2"
		--> "Volume(s) mounted successfully"
end tell
Result:
"Volume(s) mounted successfully"

I've looked up the error and it seems to be a privilege violation error.

Could anyone elaborate what I am doing wrong and how I am able to fix this error?
 
do shell script is part of Standard Additions. Move your do shell script statements out of the tell application "Finder" block. Do something like this :

Code:
tell application "Finder" to set isMounted to exists disk myVolumeLabel
if not isMounted then
--statements
else
--statements
end if
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.