阅读:2201回复:3
如何加按钮,点击则执行指定路径下exe程序
是加一个按钮 不是加菜单 就一个按钮 点击就运行外部程序exe
这个按钮可以拖到附加组件栏 哪位大神知道怎么写这个脚本? |
|
1楼#
发布于:2013-06-24 13:13
撤销按钮.uc.js 也是加一个按钮,点击执行撤销操作,可否修改为执行指定exe
下面这个加到手势里有效: var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile); file.initWithPath("程序路径"); file.launch(); 程序路径写法如D:\\Program Files\\Notepad++\\Notepad++.exe 注意是双斜杠 |
|
2楼#
发布于:2013-06-24 13:13
// ==UserScript==
// @name externalApplications.uc.js // @namespace ithinc#mozine.cn // @description External Applications // @include main // @compatibility Firefox 3.5.x 3.6.x // @author ithinc // @version 20091216.1.0.0 Final release // @version 20091215.0.0.2 Handle toolbar apps and menu apps separately // @version 20091212.0.0.1 Initial release // ==/UserScript== /* :::: External Applications :::: */ var gExternalApplications = { toolbar: { apps: [ //{name: 'Notepad', path: '/WINDOWS/system32/notepad.exe'}, {name: '计算器', path: 'C:\\WINDOWS\\system32\\calc.exe'}, //{name: 'Internet Explorer', path: 'C:\\Program Files\\Internet Explorer\\IEXPLORE.EXE', args: ['%u']}, //{name: 'Command Prompt', path: 'C:\\WINDOWS\\system32\\cmd.exe'}, ], insertafter: 'status-bar' //'menubar-items' or 'home-button' or 'addonbar-closebutton' }, init: function() { this.handleRelativePath(this.toolbar.apps); if (this.toolbar.apps.length > 0) { var refNode = document.getElementById(this.toolbar.insertafter); if (refNode) { refNode.parentNode.insertBefore(this.createToolbaritem(this.toolbar.apps), refNode.nextSibling); } } }, handleRelativePath: function(apps) { for (var i=0; i<apps.length; i++) { if (apps.path) { apps.path = apps.path.replace(/\//g, '\\'); var ffdir = Cc['@mozilla.org/file/directory_service;1'].getService(Ci.nsIProperties).get('CurProcD', Ci.nsIFile).path; if (/^(\.)/.test(apps.path)) { apps.path = ffdir + '\\' + apps.path; } else if (/^(\\)/.test(apps.path)) { apps.path = ffdir.substr(0,2) + apps.path; } } } }, exec: function(path, args) { args = args || []; for (var i=0; i<args.length; i++) { args = args.replace(/%u/g, gBrowser.currentURI.spec); } var file = Cc['@mozilla.org/file/local;1'].createInstance(Ci.nsILocalFile); file.initWithPath(path); if (!file.exists()) { Cu.reportError('File Not Found: ' + path); return; } if (!file.isExecutable()) { file.launch(); } else { var process = Cc['@mozilla.org/process/util;1'].createInstance(Ci.nsIProcess); process.init(file); process.run(false, args, args.length); } for (var i=0; i<args.length; i++) { args = '%u'; } }, createToolbaritem: function(apps) { var toolbaritem = document.createElement('toolbaritem'); toolbaritem.setAttribute('class', 'chromeclass-toolbar-additional'); toolbaritem.setAttribute('orient', 'horizontal'); for (var i=0; i<apps.length; i++) { if (apps.name == 'separator') { toolbaritem.appendChild(document.createElement('toolbarseparator')); } else { var item = toolbaritem.appendChild(document.createElement('toolbarbutton')); item.setAttribute('class', 'toolbarbutton-1 chromeclass-toolbar-additional'); item.setAttribute('label', apps.name); item.setAttribute('image', 'moz-icon:file://' + apps.path + '?size=16;'); item.setAttribute('oncommand', 'gExternalApplications.exec(this.path, this.args);'); item.setAttribute('tooltiptext', apps.name); item.setAttribute('style','margin: 0px -4px;background: none;box-shadow: none;border-color: transparent;'); //dawlen add item.path = apps.path; item.args = apps.args; } } return toolbaritem; }, }; gExternalApplications.init(); 貌似这个不支持中文路径,求解决 |
|
3楼#
发布于:2013-06-24 13:13
|
|
|