使用平板窗口管理器启动或集中应用程序?

时间:2014-11-17 17:19:04

标签: macos

我最近开始在Mac OS上使用slate window manager。我以前在Quicksilver中使用了触发器来启动或关注特定应用。

也就是说,如果cmd + f2没有运行,它会启动“谷歌浏览器”,或者如果它已经在运行,它会专注于“谷歌浏览器”。

是否有一种简单/惯用的方式来实现与Slate相同的效果?

我的.slate.js包含

"f2:cmd": S.op("focus", {"app": "Google Chrome"}),
"f4:cmd": S.op("focus", {"app": "Jump Desktop"}),

我可以将其更改为:

var runIfMap  = {
    "Jump Desktop": "/Applications/Jump Desktop.app",
    "Google Chrome": "/Applications/Google Chrome.app"
};

function runIf(name) {
    var running = false;
    slate.eachApp(function (app) {
        if (app.name() == name) {
            running = true;
        }
    });
    if (running) {
        slate.log(name + " is running");
    } else {
        slate.log(name + " is not running");
        if (runIfMap[name]) {
            var str = "/usr/bin/open \"" + runIfMap[name] + "\"";
            slate.log("running [" + str + "]");
            slate.shell(str);
        }
    }
}

"f2:cmd": function() {
    runIf("Google Chrome");
    S.op("focus", {"app": "Google Chrome"}).run();
},

"f4:cmd": function() {
    runIf("Jump Desktop");
    S.op("focus", {"app": "Jump Desktop"}).run();
},

但这似乎很麻烦。

我是在问石板做得太多还是我错过了一种更明显的方法来实现我的目标?

1 个答案:

答案 0 :(得分:0)

我不完全确定,你的例子有什么问题,但是如果没有运行,Slate会启动应用程序。也许您必须声明slate.shell方法的所有参数。

slate.config("orderScreensLeftToRight", true);
 
// Create Operations
var pushRight2_3 = slate.operation("push", {
  "direction" : "right",
  "style" : "bar-resize:3*screenSizeX/5"
});
var pushLeft1_3 = slate.operation("push", {
  "direction" : "left",
  "style" : "bar-resize:2*screenSizeX/5"
});
 
var devLayout = slate.layout("devLayout", {
  "iTerm" : {
    "operations" : [pushLeft1_3],
    "repeat" : true
  },
  "Sublime Text" : {
    "operations" :[pushRight2_3],
    "repeat" : true
  }
});
 
slate.bind("1:cmd;ctrl", function() { setDev(); });

slate.default(["1440*900"], devLayout);
 
var runIfMap  = {
    "iTerm": "/opt/homebrew-cask/Caskroom/iterm2/2.0/iTerm.app",
    "Sublime Text": "/Applications/Sublime Text.app"
};
 
function runIf(name) {
    var running = false;
    slate.eachApp(function (app) {
        if (app.name() == name) {
            running = true;
        }
    });
    if (!running) {
      slate.shell("/usr/bin/open " + '"' + runIfMap[name] + '"', true, "~/");
    }
}
 
function setDev() {
  runIf("iTerm");
  runIf("Sublime Text");
  var op = slate.operation("layout", { "name" : devLayout });
  op.run();
}

重点应放在最后推出的应用程序上。