def_get_localized_name(abs_path): '''get the localized name of given app''' bundle = NSBundle.new() bundle.initWithPath_(abs_path) localizations = bundle.localizations() chinese = ('zh_CN', 'zh_Hans')
b = any(map(lambda x: x in localizations, chinese)) ifnot b: return
for ch in chinese: path = bundle.pathForResource_ofType_inDirectory_forLanguage_('InfoPlist', 'strings', None, ch) ifnot path: continue # the path must surround with "", there may be space characters json_str = subprocess.check_output(u'plutil -convert json -o - "%s"' % path, shell=True) # print json_str json_res = json.loads(json_str, encoding='utf8') name = json_res.get('CFBundleName') if name: return name
def_get_app_pinyin_name(app_name): reduce(lambda x, y: x + y, lazy_pinyin(app_name, errors='ignore'))
添加拼音信息
拼音信息被添加到文件的拓展信息里面,直接使用xattr添加即可:
1 2 3
def_add_meta_data(app_pinyin_name, app_path): ''' add meta data(comments) to the app, which can help Alfred or SpotLight find it''' subprocess.check_call('xattr -w com.apple.metadata:kMDItemFinderComment %s %s' % (app_pinyin_name, app_path), shell=True)
if pattern.match(app_name): continue _add_meta_data(_get_app_pinyin_name(app_name), full_path)
# if this directory is already a Application # do not traverse this; some app may be very large # and there won't be any other app inside it dirs[:] = [d for d in dirs if d notin remove_list]