Mount encrypted partition with Terminal -> privilege violation error

Discussion in 'Mac Programming' started by Stiruam, Jul 21, 2014.

  1. Stiruam macrumors newbie

    Joined:
    Jul 28, 2010
    #1
    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?
     
  2. kryten2 macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    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
     

Share This Page