Created
March 27, 2012 06:51
-
-
Save shiroyuki/2213462 to your computer and use it in GitHub Desktop.
Duplicated App Finding Script for Launchpad on Mac OS X 10.7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
Find and provide command to remove a duplicate app icon on Launchpad for Mac OS X 10.7. | |
:Author: Juti Noppornpitak <[email protected]> | |
:Copyright: Juti Noppornpitak <[email protected]> | |
Prerequisites | |
------------- | |
pip install sqlalchemy | |
pip install https://github.com/shiroyuki/Tori/zipball/master | |
License | |
------- | |
Copyright (C) 2012 Juti Noppornpitak | |
Permission is hereby granted, free of charge, to any person obtaining a copy of this software | |
and associated documentation files (the "Software"), to deal in the Software without restriction, | |
including without limitation the rights to use, copy, modify, merge, publish, distribute, | |
sublicense, and/or sell copies of the Software, and to permit persons to whom the Software | |
is furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in all copies or | |
substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING | |
BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, | |
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | |
''' | |
from os import environ as env | |
from os.path import abspath, dirname, join | |
from glob import glob | |
probing_path = join(env.get('HOME'), 'Library/Application Support/Dock/*.db') | |
db_path = glob(probing_path) | |
if db_path: | |
db_path = db_path[0] | |
from sqlalchemy import Table, MetaData, Column, ForeignKey, Integer, String, types | |
from tori.service.rdb import BaseEntity, RelationalDatabaseService | |
class DockedApp(BaseEntity): | |
''' | |
Command Line | |
------------ | |
``sqlite3 93C251D3-FBE8-4F7F-90B9-761C2121BF22.db ".schema table apps"`` | |
Original Schema | |
--------------- | |
.. code-block::sql | |
CREATE TABLE apps ( | |
item_id INTEGER PRIMARY KEY, | |
title VARCHAR, | |
bundleid VARCHAR, | |
storeid VARCHAR, | |
category_id INTEGER, | |
moddate REAL, | |
bookmark BLOB | |
); | |
''' | |
__tablename__ = 'apps' | |
item_id = Column(Integer, primary_key=True) | |
title = Column(String) | |
bundle_id = Column('bundleid', String) | |
store_id = Column('storeid', String) | |
category_id = Column(Integer) | |
moddate = Column(types.REAL) | |
bookmark = Column(types.BLOB) | |
def __init__(self, item_id, title, bundle_id, store_id, category_id, moddate, bookmark): | |
self.item_id = item_id | |
self.title = title | |
self.bundle_id = bundle_id | |
self.store_id = store_id | |
self.category_id = category_id | |
self.moddate = moddate | |
self.bookmark = bookmark | |
def __repr__(self): | |
return '<DockedApp [%d] "%s">' % (self.item_id, self.title) | |
db_url = 'sqlite:///%s' % db_path | |
db = RelationalDatabaseService(db_url) | |
session = db.session() | |
apps = session.query(DockedApp).order_by(DockedApp.title).all() | |
session.close() | |
known_apps = set() | |
targets = [] | |
for app in apps: | |
if app.title in known_apps: | |
targets.append(app) | |
continue | |
print '%45s | %4d | %s' % (app.title, app.item_id, app.bundle_id) | |
known_apps.add(app.title) | |
for target in targets: | |
print 'To delete a duplicate of %s' % target.title | |
print 'sqlite3 "%s" "DELETE FROM apps WHERE item_id=%d"' % (db_path, target.item_id) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment