Last active
November 28, 2021 15:11
-
-
Save organicaudio/9726affd4f7e37ff172d737a2fb3886a to your computer and use it in GitHub Desktop.
Time Machine - Mount Remote SparseBundle (AppleScript)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- VAR: | |
| set nameBackup to "YourHostName Backups" | |
| set pathBackup to "/Volumes/nameBackup/" | |
| set pathVolume to "smb://user@REMOTEHOST._smb._tcp.local/time_machine" | |
| set pathSparseBundle to "/Volumes/time_machine/HOSTNAME.sparsebundle" | |
| -- SCRIPT: | |
| tell application "System Events" to set diskNames to name of every disk | |
| if nameBackup is in diskNames then | |
| -- backup destination not mounted; take no action | |
| display dialog "" & nameBackup & " - disk exists - no action taken" buttons {"OK"} default button 1 with icon 1 | |
| else | |
| -- backup destination not mounted; mount remote volume than mount disk image | |
| display dialog "" & nameBackup & " - disk does not exist - mounting..." buttons {"OK"} default button 1 with icon 1 | |
| try | |
| -- mount remote volume | |
| mount volume pathVolume | |
| end try | |
| -- mount (timemachine) sparsebundle image | |
| do shell script "hdiutil attach -mountpoint " & quoted form of POSIX path of pathBackup & " " & quoted form of POSIX path of pathSparseBundle | |
| -- validate remote mount & diskimage attach was successful | |
| tell application "System Events" to set diskNames to name of every disk | |
| if nameBackup is in diskNames then | |
| -- previous actions were successful | |
| display dialog "" & nameBackup & " - disk now mounted" buttons {"OK"} default button 1 with icon 1 | |
| else | |
| -- failure: something broke or remote volume not available. user debug required | |
| display dialog "" & nameBackup & " - FAILURE - remote vol not available or something broke. please debug and try again" buttons {"OK"} default button 1 with icon 1 | |
| end if | |
| end if |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TL;DR This script simplifies the use of an (encrypted) Sparse Bundle Disk Image as a destination for macOS (Time Machine) & iOS (iMazing) device backups using a Samba share.
LANGUAGE: AppleScript
Logic:
Background:
Usage:
Localize these variables
nameBackup = name of the mounted sparsebundle disk image (eg. YourHostName Backups)
pathBackup = almost always will be the name above preceeded by /Volumes/
pathVolume = remote path (eg. smb) to mountable share containing SparseBundle file.
(if possible use the Bonjour / Avahi advertised path to smb (that is how Time Machine detects the path without user action)
pathSparseBundle = local mounted path of remote volume and the remaining path to sparsebundle disk image
Create executable Application using Script Editor
See this guide for details https://support.apple.com/en-ca/guide/script-editor/scpedt1072/2.11/mac/12.0
By default macOS Script Editor saves files locally in $HOME/Library/Scripts/
Run from command line:
Execute - Local path:
Execute - iCloud path:
Run as Application:
run from inside gui :)
Run on Calendar Event trigger:
Script can be set to run when a calendar event occurs (think of it as an easy method of cron jobs in macOS) See this guide for a how-to if unfamiliar https://www.idownloadblog.com/2018/10/19/mac-calendar-open-file-alerts/
Changes required for running script scheduled / headless is to remove
display dialogentries except final one (that would advise you on failure) since they function as a wait until user responds.The script would be triggered by the calendar event (say one every 12hours or right before scheduled backup time). Checking if action required, if yes execute mount / attach, validate success, and all the while being silent. Script would only alert user if a failure occurred (disk wasn't mounted, script tried to mount it, but ultimately failed)