Skip to content

Instantly share code, notes, and snippets.

@esquifit
Forked from esquifit/open_folder.ubiq.js
Created May 2, 2010 18:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esquifit/387358 to your computer and use it in GitHub Desktop.
Save esquifit/387358 to your computer and use it in GitHub Desktop.
Opens Firefox special folder (profile, chrome or installaton folder) For Ubiquity 0.5
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({
names: ['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.',
arguments: [{ role: 'object',
label: 'Folder type',
nountype: noun_type_folder }],
preview: function(pblock, args) {
pblock.innerHTML = 'Open ' + args.object.text;
},
execute: function(args) {
switch(args.object.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