Search code examples
macosapplescriptosx-mountain-lionhdiutil

AppleScript throwing error on hdiutil command


I have the following code in an AppleScript file, which should mount a sparsebundle hosted on my network. Running this script throws an error on the hdiutil command:

try
  mount volume "smb://192.168.1.1/sda2"
end try

do shell script "hdiutil attach -mountpoint /Volumes/sda2 timemachine.sparsebundle"

The error I'm receiving is:

hdiutil: attach failed - No such file or directory" number 1

Running the shell script code in Terminal works just fine, and the script builds fine. Any ideas?


Solution

  • Got it working. I changed the hdiutil command syntax and now AppleScript does not throw an error.

    try
      mount volume "smb://192.168.1.1/sda2"
    end try
    
    do shell script "hdiutil attach /Volumes/sda2/timemachine.sparsebundle/"
    

    Not sure why the original command still works in Terminal but fails in AppleScript, but at least it works now.