A better way to make Automator mount a volume?

Discussion in 'Mac Applications and Mac App Store' started by whitman, May 1, 2013.

  1. macrumors newbie

    Joined:
    Jan 4, 2008
    #1
    I'm new to Automator (10.8.3). I made an Automator application, using the Record function, to mount a volume on a drive connected to my Mini. I also made a similar one to eject it. I use them as Calendar-triggered events as part of my backup scheme.

    They work well ... until I restart the Mini, when occasionally my two connected drives will mount in a different order. What happens then is that the sequence of mouse clicks recorded in Automator don’t find the correct volume.

    I wonder if there’s a better way to automate the mounting of a currently ejected disc (and later its ejection). Automator, as far as I can see, does not have the actions I need. It has Ask For/Connect to/Get specified Servers, but they seem only to be for network-connected stuff.

    Anyone know a better way?
     
  2. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #2
    Check out the diskutil and hdiutil commands. Launch the Terminal application and type in man diskutil or man hdiutil, press enter. You can use them in a shell script or with Applescript's do shell script command.

    Info : man page for diskutil and man page for hdiutil
     
  3. thread starter macrumors newbie

    Joined:
    Jan 4, 2008
    #3
    Thanks kryten. I found Automator uphill, but this is beyond me, I think. Can you explain what I'd need to do?
     
  4. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #4
    I can try if you provide more information but it's not going to be easy. Search for Terminal in Spotlight. Launch it and paste or type the following line into the Terminal window with your two drives connected to your Mac and press enter :

    Code:
    diskutil list 
    The command should return some output like in the example attached tumbnail. Make a screenshot of the Terminal window and attach it to your reply. Provide more information as to which volume you would like to mount or unmount. Also attach your Automator app to your reply but save it first as a workflow.
     

    Attached Files:

  5. thread starter macrumors newbie

    Joined:
    Jan 4, 2008
    #5
    Kryten, much appreciated. There's a screenshot below of the Terminal window as instructed.

    The volume I want to mount and to eject is "CLONE SprDpr".

    I've also attached my Automator app.
     

    Attached Files:

  6. kryten2, May 2, 2013
    Last edited: May 2, 2013

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #6
    Can you explain what your Calendar event does? Judging by the volume name and you stating it's part of your backup scheme I think it has something to do with super duper. The part of using disk utility to mount the volume I get but the rest is a bit of a mystery. I'm also a bit baffled by the fact that you have to manually mount/unmount a volume. When you connect an external disk all volumes should automount and show in the Finder. When you eject a disk that disk is no longer visible to the system. The only way to make an ejected disk visible again is to unplug and plug it back. You can try this GUI Applescript if you want. Search for Applescript Editor. You need to check enable access for assistive devices in Accessibility pane of System Preferences for this to work and your disk should be visible to the system. It will try to mount/unmount your "CLONE SprDpr" volume.


    Code:
    set theExitStatus to do shell script "mount | grep CLONE 1> /dev/null ; echo $?"
    
    activate application "Disk Utility"
    tell application "System Events"
    	tell process "Disk Utility"
    		set frontmost to true
    		-- insert GUI Scripting statements here
    		set myOutline to outline 1 of scroll area 1 of splitter group 1 of window "Disk Utility"
    		set allRows to rows in myOutline
    		set diskNameVals to value of static text of every row in myOutline
    		repeat with i from 1 to (count diskNameVals)
    			set diskNameVal to item 1 of item i of diskNameVals
    			if (diskNameVal as string = "CLONE SprDpr") then
    				tell row i of myOutline
    					select
    					delay 2
    				end tell
    				if theExitStatus = "1" then
    					keystroke "M" using {command down, shift down}
    				else
    					keystroke "U" using {command down, shift down}
    				end if
    			end if
    		end repeat
    	end tell
    end tell
    
    delay 5
    tell application "Disk Utility" to quit
    
     

    Attached Files:

  7. thread starter macrumors newbie

    Joined:
    Jan 4, 2008
    #7
    Kryten, the Calendar event mounts the ejected volume of my WD Firewire-connected drive, just before my scheduled SuperDuper backup. It also runs a little later to eject the volume once again.

    The bits that aren't identified in the sequence are the mouse-clicks to get to Disk Utility, and to close various windows afterward.

    I don't want my drives mounted the rest of the time because they are noisy, even when idle, and distracting from my work.

    As I said in my original post, this is all working fine ... except when I occasionally and inevitably have a restart, and my two connected drives then decide to mount in a different order. Then the sequence of mouse clicks recorded in Automator will not find the correct volume. So I've been looking for another way to do the same thing that doesn't need to physically find the correct volume in Disk Utility.

    I'm not sure your script takes that into account, or do I misunderstand you?
     
  8. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #8
    Did you run the script? Does it do what your Calendar event does? Did you look at the screenrecordings? Trust me it will not blow up your Mac it will only try to mount/unmount your "CLONE SprDpr" volume. If it`s ejecting that you want the script can be modified. Post a screenshot of Disk Utility with a numbered sequence of arrows.

    1. Select the "CLONE SprDpr" volume
    2. Click mount
    3. Do my Super Duper thing
    4. Select my "CLONE SprDpr" volume or the disk it resides on
    5. Click Unmount or Eject. There is a difference in result.
     

    Attached Files:

  9. thread starter macrumors newbie

    Joined:
    Jan 4, 2008
    #9
    Kryten, your powers are intact. I ran the script and it works perfectly to mount the volume - wherever it may reside in Disk Utility. Thank you!

    Two more things I need to know, I think.
    1. How do I modify the script to make a script to eject the same volume.
    2. How do I then deploy the scripts as Calendar-triggered events?

    I'm not clear what you mean by the numbered sequence.
     
  10. kryten2, May 3, 2013
    Last edited: May 3, 2013

    macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #10
    Thank you for trying the script and your feedback so you can forget about that numbered sequence.

    1. Run the script again. It will unmount the volume. Can you try this and see if the result is satisfactory?
    2. I'm working on my old G4 Mac mini right now. I'll fire up a ML machine to see if Calendar still supports running Applescripts. I'll also test putting the script into Automator. I'll let you know the results.

    Edit : In Automator make a new Calendar Alarm with a Run Applescript action. Remove the on run handler part and copy the code from the script into the Run Applescript action. See attached tumbnail.
     

    Attached Files:

  11. thread starter macrumors newbie

    Joined:
    Jan 4, 2008
    #11
    Thanks Kryten. I've run the script again and it does indeed eject as well. Perfect.

    I'm not quite with you on creating the Run Applescript action. Not sure what you mean by "remove the on run handler part".
     
  12. macrumors 6502a

    Joined:
    Mar 17, 2012
    Location:
    Belgium
    #12
    Example :
     

    Attached Files:

  13. thread starter macrumors newbie

    Joined:
    Jan 4, 2008
    #13
    Ta, Kryten. Me being dim. Everything is working fine. Thanks so much for your patience and help. Very much appreciated.
     
  14. macrumors regular

    Joined:
    Apr 26, 2011
    #14
    Good for you kryten2 - its nice to see someone being so helpful
     

Share This Page