WD MyBook AppleScript: Auto Unlock & Time Machine

  • What is it?

    An AppleScript that you can use to automate the unlocking of and Time Machining to your encrypted Western Digital MyBook external hard drive on a Mac.

    When you attach or switch on the hard drive, this script automagically starts the unlock application, unmounts the Unlocker volume when done, and asks if you want to directly start your Time Machine backup.

    Please let us know if it works good for you!


    Why we built it

    To be able to combine hardware-encrypted Time Machine backups and ease of use. If we have to click too often, we will make fewer backups, so this script makes our data safer.

  • Can I help?

    Yes! We'd be glad to receive upgraded, extended or otherwise improved versions of this script. Any improvements that are submitted will be considered to be featured in the version we serve.


    How can I thank you guys?

    You don't have to, but you are free to donate some money. Any donations will be lent to entrepreneurs around the world as microcredit through Kiva at least three times.

    It means a lot to us if you follow us on Twitter or if you buy our BubbleShooter for iOS, so those are great ways to say 'thank you' as well!
  • License

    This AppleScript is licensed under the MIT License.

    That boils down to:
    - You are free to do with this code what you want, personally or commercially.
    - You are not required to release modifications, extensions or updates to the code (but it'd be great if you would).
    - You must keep the original copyright notice intact in all instances of the code.
    - The software is provided "as is"; we are never liable for any damage it causes.

    Full MIT License

  • Download

    Did you read the license info?
    Download AppleScript


    5-step installation guide

    1. Download the file above and unpack it
    2. Place WDUnlocker.scpt file in /Library/Scripts/Folder Action Scripts/
    3. In your Finder, navigate to /Volumes/ (you can use Cmd+Shift+G)
    4. Right-click the /Volumes/ directory and choose 'Folder Actions Setup'
    5. Choose 'WDUnlocker.scpt' and click 'Attach'. Make sure 'Enable Folder Actions' in the top of the window is checked.

    That's it! Now, whenever you connect or switch on the drive and the WDUnlocker volume is auto-mounted, the AppleScript will take over and allow you to enter your password and start the Time Machine backup easily.

The script



For easy reference, here is the AppleScript in its entirety.
We are not exactly AppleScript gurus so please let us know if you see room for improvement!

--
-- This script should be attached to the /Volumes/ folder as a Folder Action.
--
on adding folder items to this_folder after receiving these_items
	
	-- First, whenever a new volume with name 'WD Unlocker' is mounted,
	-- this script tries to run 'DriveUnlock.app'
	repeat with aItem in these_items
		tell application "Finder"
			if (local volume of aItem) and (name of aItem is "WD Unlocker") then
				set file_list to every file of entire contents of aItem
				repeat with aFile in file_list
					if (name of aFile is "DriveUnlock.app") then
						open aFile
					end if
				end repeat
			end if
		end tell
	end repeat
	
	-- Then, wait for the unlock app to finish executing
	set unlockerRunning to true
	repeat until unlockerRunning = false
		tell application "System Events"
			set unlockerRunning to (application process "DriveUnlock" exists)
			delay 1
		end tell
	end repeat
	
	-- Now unmount the unlocker volume
	do shell script "diskutil unmount \"WD Unlocker\""
	
	-- And start Time Machine backups if user wants to
	set question to display dialog "Start Time Machine backup?" buttons {"Yes", "No"} default button 2
	set answer to button returned of question
	
	if answer is equal to "Yes" then
		do shell script "/System/Library/CoreServices/backupd.bundle/Contents/Resources/backupd-helper >/dev/null 2>&1 &"
	end if
	
end adding folder items to

Twitter

Follow me
Dubble - Bubbleshooter Revolution

The best bubbleshooter for iOS and Mac

Dubble is the best rated bubbleshooter in the App Store. For just $3.99 you get a universal app (for iPhone, iPod Touch and iPad) with 3 singleplayer games and 1 amazing multiplayer game, in which 2 players can play Dubble on a single device. Visit the website for the trailer and more information!

"Beautiful and challenging", "The best bubble shooter I've ever played", "The two-player mode is AWESOME", "Get this game, it's very fun!"

Dubble in the AppStore

 



Dubble Website