Guest User

Untitled

a guest
Apr 28th, 2018
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. property knownMACID : {}
  2. property knownTMVolumesPath : {}
  3. property vers : "0.2"
  4.  
  5.  
  6. (*
  7.  
  8.  
  9. .2:
  10. Added faster routine, for geting router MAC Adddress, from @seesolve on twitter
  11. .1:
  12. First Working Demo of script, only shows you whats going to happen, does not actually do backup.
  13.  
  14.  
  15. *)
  16. on getgetroutermac()
  17.     return (do shell script "arp `netstat -r -f inet | awk '/^default/ {print $2}'` | cut -f4 -d\" \"")
  18. end getgetroutermac
  19.  
  20. on getmyip()
  21.     return (IPv4 address of (system info))
  22. end getmyip
  23.  
  24. on run {}
  25.     set ISON_knownMACID to 0
  26.     repeat with i from 1 to length of knownMACID
  27.         if item i of knownMACID = getmyip() then
  28.             set ISON_knownMACID to i
  29.             exit repeat
  30.         end if
  31.     end repeat
  32.    
  33.     if ISON_knownMACID ≠ 0 then
  34.         display dialog getmyip() & "  " & item (ISON_knownMACID) of knownTMVolumesPath
  35.        
  36.         display dialog "tmutil setdestination \"" & item (ISON_knownMACID) of knownTMVolumesPath & "\""
  37.         --do shell script "tmutil setdestination \"" & item (ISON_knownMACID) of knownTMVolumesPath & "\"" with administrator privileges
  38.         delay 2
  39.         display dialog "this is where we verify to make sure time machine is on"
  40.         --do shell script "tmutil enable" with administrator privileges
  41.         delay 3
  42.         display dialog "And this is where we start a backup"
  43.         --do shell script "tmutil startbackup" with administrator privileges
  44.        
  45.     else
  46.         set temp1 to getmyip()
  47.         set temp2 to TMBackupVolume()
  48.         if temp2 does not contain "ERR:" then
  49.             display dialog "This location is new, adding the following info:
  50. " & temp1 & "
  51. " & temp2
  52.             set end of knownMACID to temp1
  53.             set end of knownTMVolumesPath to temp2
  54.         else
  55.             display dialog temp2 as string
  56.         end if
  57.     end if
  58. end run
  59. on TMBackupVolume()
  60.     try
  61.         set ON_ERROR to false
  62.         set tmutilresponse to (do shell script "tmutil latestbackup")
  63.     on error errorreturned
  64.         set ON_ERROR to true
  65.         display dialog errorreturned
  66.     end try
  67.     if ON_ERROR = false then
  68.         return (item 1 of stringtolist(tmutilresponse, "Backups.backupdb"))
  69.     else
  70.         return ("ERR: " & errorreturned)
  71.     end if
  72. end TMBackupVolume
  73.  
  74. on stringtolist(theString, delim)
  75.     set oldelim to AppleScript's text item delimiters
  76.     set AppleScript's text item delimiters to delim
  77.     set dlist to (every text item of theString)
  78.     set AppleScript's text item delimiters to oldelim
  79.     return dlist
  80. end stringtolist
  81. on ListToString(theList, delim)
  82.     set oldelim to AppleScript's text item delimiters
  83.     set AppleScript's text item delimiters to delim
  84.     set alist to theList as string
  85.     set AppleScript's text item delimiters to oldelim
  86.     return alist
  87. end ListToString
Add Comment
Please, Sign In to add comment