Created
December 22, 2009 21:19
-
-
Save esquifit/262058 to your computer and use it in GitHub Desktop.
Opens Firefox special folder (profile, chrome or installaton folder) For Ubiquity 0.1.9
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
function openSpecialFolder(aFolderType) { | |
var dirService = Components.classes['@mozilla.org/file/directory_service;1'] | |
.getService(Components.interfaces.nsIProperties); | |
var dir = dirService.get(aFolderType, Components.interfaces.nsIFile); | |
var iDirectory = getLocalFileInterface(dir.path); | |
try { | |
iDirectory.reveal(); | |
} catch (ex) { | |
// if reveal failed for some reason (eg on unix it's not currently | |
// implemented), send the file: URL to the OS handler for that protocol | |
var uri = Components.classes["@mozilla.org/network/io-service;1"] | |
.getService(Components.interfaces.nsIIOService) | |
.newFileURI(iDirectory); | |
var protocolSvc = Components.classes["@mozilla.org/uriloader/external-protocol-service;1"] | |
.getService(Components.interfaces.nsIExternalProtocolService); | |
protocolSvc.loadUrl(uri); | |
} | |
}; | |
function getLocalFileInterface(filePath) { | |
try { | |
var localFileInterface = Components.classes["@mozilla.org/file/local;1"] | |
.createInstance(Components.interfaces.nsILocalFile); | |
localFileInterface.initWithPath(filePath); | |
return localFileInterface; | |
} catch (ex) { | |
return null; | |
} | |
}; | |
noun_type_folder = new CmdUtils.NounType( 'Folder Type', [ "Profile", "Chrome", "Installation" ]); | |
CmdUtils.CreateCommand({ | |
name: 'open-folder', | |
icon: 'chrome://global/skin/icons/folder-item.png', | |
//homepage: | |
author: {name: 'esquifit'}, | |
license: 'Public Software', | |
description: 'Opens Firefox special folder (profile, chrome or installaton folder)', | |
help: 'Select desired folder type. If no folder type is given, "profile" is assumed.', | |
takes: {'Folder type': noun_type_folder}, | |
preview: function(pblock, folderType) { | |
pblock.innerHTML = 'Open ' + folderType.text; | |
}, | |
execute: function(folderType) { | |
switch(folderType.text){ | |
case 'Chrome': type = 'UChrm'; break; | |
case 'Installation': type = 'CurProcD'; break; | |
default: type = 'ProfD'; | |
} | |
//displayMessage("Selected type: " + type); | |
openSpecialFolder(type); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment