okokpypy
小狐狸
小狐狸
  • UID39385
  • 注册日期2013-04-15
  • 最后登录2013-09-26
  • 发帖数33
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度1点
阅读:1810回复:3

如何加按钮,点击则执行指定路径下exe程序

楼主#
更多 发布于:2013-06-24 13:13
是加一个按钮 不是加菜单 就一个按钮 点击就运行外部程序exe
这个按钮可以拖到附加组件栏  哪位大神知道怎么写这个脚本?
okokpypy
小狐狸
小狐狸
  • UID39385
  • 注册日期2013-04-15
  • 最后登录2013-09-26
  • 发帖数33
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度1点
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 注意是双斜杠
okokpypy
小狐狸
小狐狸
  • UID39385
  • 注册日期2013-04-15
  • 最后登录2013-09-26
  • 发帖数33
  • 经验10枚
  • 威望0点
  • 贡献值0点
  • 好评度1点
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();

貌似这个不支持中文路径,求解决
brucmao
火狐狸
火狐狸
  • UID39549
  • 注册日期2013-05-29
  • 最后登录2020-03-25
  • 发帖数101
  • 经验154枚
  • 威望0点
  • 贡献值134点
  • 好评度5点
3楼#
发布于:2013-06-24 13:13
@brucmao
游客

返回顶部