Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- PATH="/var/mobile/applink"
- import sys,os,objc # PyObjC; this is a dependency of the AppBackup package
- from objc import YES, NO, NULL
- objc.loadBundle("Foundation", globals(), "/System/Library/Frameworks/Foundation.framework")
- # a class to work with plists using Foundation (so we can read binary plists)
- class plist:
- @classmethod
- def read(cls, filename):
- return NSDictionary.alloc().initWithContentsOfFile_(filename)
- # Gets the info from the MobileInstallation cache.
- def find_apps():
- if not os.path.exists("/var/mobile/Library/Caches/com.apple.mobile.installation.plist"):
- sys.stdout.write("MobileInstallation cache not found; reverting to old method of finding apps...\n")
- find_apps_old()
- return
- try:
- mobileInstallationCache = plist.read("/var/mobile/Library/Caches/com.apple.mobile.installation.plist")
- except:
- sys.stdout.write("Reading the MobileInstallation cache failed; reverting to old method of finding apps...\n")
- find_apps_old()
- return
- if "User" not in mobileInstallationCache:
- sys.stdout.write("MobileInstallation cache doesn't have a User key; reverting to old method of finding apps...\n")
- find_apps_old()
- return
- appStoreApps = mobileInstallationCache["User"]
- sys.stdout.write("Here are the app bundles I found:\n")
- for key in appStoreApps:
- i = appStoreApps[key]
- path = "/".join(i["Path"].rstrip("/").split("/")[:-1])
- if os.path.exists(path) and "CFBundleDisplayName" in i and i["CFBundleDisplayName"] != "":
- #dotApp = i["Path"].rstrip("/").split("/")[-1]
- #dotAppFull = path + "/" + dotApp
- if path.startswith("/private"):
- path = path.split("/private", 1)[1]
- guid = path.split("/")[-1]
- sys.stdout.write(guid+"\n")
- try:
- os.symlink(path,i["CFBundleDisplayName"])
- except:
- sys.stdout.write("Duplicate name\n")
- os.symlink(path,i["CFBundleDisplayName"]+"_"+guid)
- def find_apps_old():
- mobile = u"/var/mobile"
- root = mobile+"/Applications"
- applist = []; applist1 = []; appdict = {}; apps = []
- apps1 = os.listdir(root)
- for i in apps1:
- if os.path.isdir(root+"/"+i) == True:
- apps.append(i)
- sys.stdout.write("Here are the app bundles and Info.plist's I found:\n")
- for k in apps:
- appdir = root+"/"+k
- for j in os.listdir(appdir):
- if j.endswith(u".app"):
- plistfile = u"%s/%s/Info.plist" % (appdir, j)
- if os.path.exists(plistfile) == True:
- pl = plist.read(plistfile)
- if "CFBundleDisplayName" in pl:
- guid = appdir.split("/")[-1]
- sys.stdout.write(guid+"\n")
- try:
- os.symlink(appdir,pl["CFBundleDisplayName"])
- except:
- sys.stdout.write("Duplicate name\n")
- os.symlink(appdir,pl["CFBundleDisplayName"]+"_"+guid)
- #main
- os.system("rm -rf \""+PATH+"\"")
- os.mkdir(PATH)
- os.chdir(PATH)
- find_apps()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement