Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- property knownMACID : {}
- property knownTMVolumesPath : {}
- property vers : "0.2"
- (*
- .2:
- Added faster routine, for geting router MAC Adddress, from @seesolve on twitter
- .1:
- First Working Demo of script, only shows you whats going to happen, does not actually do backup.
- *)
- on getgetroutermac()
- return (do shell script "arp `netstat -r -f inet | awk '/^default/ {print $2}'` | cut -f4 -d\" \"")
- end getgetroutermac
- on getmyip()
- return (IPv4 address of (system info))
- end getmyip
- on run {}
- set ISON_knownMACID to 0
- repeat with i from 1 to length of knownMACID
- if item i of knownMACID = getmyip() then
- set ISON_knownMACID to i
- exit repeat
- end if
- end repeat
- if ISON_knownMACID ≠ 0 then
- display dialog getmyip() & " " & item (ISON_knownMACID) of knownTMVolumesPath
- display dialog "tmutil setdestination \"" & item (ISON_knownMACID) of knownTMVolumesPath & "\""
- --do shell script "tmutil setdestination \"" & item (ISON_knownMACID) of knownTMVolumesPath & "\"" with administrator privileges
- delay 2
- display dialog "this is where we verify to make sure time machine is on"
- --do shell script "tmutil enable" with administrator privileges
- delay 3
- display dialog "And this is where we start a backup"
- --do shell script "tmutil startbackup" with administrator privileges
- else
- set temp1 to getmyip()
- set temp2 to TMBackupVolume()
- if temp2 does not contain "ERR:" then
- display dialog "This location is new, adding the following info:
- " & temp1 & "
- " & temp2
- set end of knownMACID to temp1
- set end of knownTMVolumesPath to temp2
- else
- display dialog temp2 as string
- end if
- end if
- end run
- on TMBackupVolume()
- try
- set ON_ERROR to false
- set tmutilresponse to (do shell script "tmutil latestbackup")
- on error errorreturned
- set ON_ERROR to true
- display dialog errorreturned
- end try
- if ON_ERROR = false then
- return (item 1 of stringtolist(tmutilresponse, "Backups.backupdb"))
- else
- return ("ERR: " & errorreturned)
- end if
- end TMBackupVolume
- on stringtolist(theString, delim)
- set oldelim to AppleScript's text item delimiters
- set AppleScript's text item delimiters to delim
- set dlist to (every text item of theString)
- set AppleScript's text item delimiters to oldelim
- return dlist
- end stringtolist
- on ListToString(theList, delim)
- set oldelim to AppleScript's text item delimiters
- set AppleScript's text item delimiters to delim
- set alist to theList as string
- set AppleScript's text item delimiters to oldelim
- return alist
- end ListToString
Add Comment
Please, Sign In to add comment