title: Running a python script on time machine to copy files
body: <p>I want to get rid of all the data in my time machine backup drive and only keep the photos. So I have written a python script for that which walks through files, finds out the photos ('png', 'jpg', etc.) and then copies those to another folder on the desktop.</p>
  
  <p>The problem is osx doesn't allow the script to access files in that drive. This is my script:</p>
  
  <pre class="lang-py prettyprint-override"><code>
  from os import path, getcwd, mkdir, walk
  from shutil import copy2, copyfile
  
  def klasorleri_gez(kynk, hdf):
      butun_icerik = walk(kynk, False)
      butun_icerik_liste = [i for i in butun_icerik]
  
      for i in range(len(butun_icerik_liste)):
          klasor = butun_icerik_liste[i]
          klasor_adresi = klasor[0]
          klasordeki_dosyalar = klasor[2]
          for dosya in klasordeki_dosyalar:
              dosya_adress = path.join(klasor_adresi, dosya)
              if '.jpg' in dosya_adress or '.png' in dosya_adress or '.jpeg' in dosya_adress:
                  print('Kopyalaniyor: ', dosya_adress)
                  copy2(dosya_adress, hdf)
  
  
  
  if __name__ == "__main__":
      HEDEF_KLASOR_ISIM = 'hedef_klasor'
      KAYNAK_KLASOR_ISIM = "/Volumes/Time{}Machine/Backups.backupdb/Kerem’s{}MacBook{}Pro{}(2)/".format(" ", " ", " ", " ")
  
      cwd = getcwd()
      hedef_klasor = path.join(cwd, HEDEF_KLASOR_ISIM)
      mkdir(hedef_klasor)
      klasorleri_gez(KAYNAK_KLASOR_ISIM, HEDEF_KLASOR_ISIM)
  </code></pre>
  
  <p>I have already tried to run it with <code>sudo</code>, <code>sudo su</code> and as a super user it's still not permitted. In <a href="https://superuser.com/questions/162690/how-can-i-delete-time-machine-files-using-the-commandline">this post</a> and <a href="https://web.archive.org/web/20130827090641/http://techjournal.318.com/general-technology/the-time-machine-safety-net/" rel="nofollow noreferrer">this page</a> it is mentioned that you can run a command with arguments using <code>/System/Library/Extensions/TMSafetyNet.kext/Contents/Helpers/bypass</code>, so I have run the following command:</p>
  
  <pre><code>Kerems-MacBook-Pro:Desktop base$ /System/Library/Extensions/TMSafetyNet.kext/Contents/Helpers/bypass ls /Volumes/Time\ Machine/Backups.backupdb/Kerem’s\ MacBook\ Pro\ \(2\)/
  ls: : Operation not permitted
  </code></pre>
  
  <p>And still no luck! Does anybody know how to overcome that permission issue?</p>
  
  <p>Thanks</p>