Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

More ways of identifying computers/screens #212

Closed
bradleywright opened this Issue · 6 comments

2 participants

Bradley Wright Jigish Patel
Bradley Wright

I have a 13" MacBook Air at home, and a 15" MacBook Pro (non-retina :cry:) at work. They have the same resolution of 1440x900, but I'd like to be able to tell them apart in a single Slate config.

Not sure what else is available to differentiate computers - hostname maybe? User login?

Jigish Patel jigish was assigned
Jigish Patel
Owner

you're in luck if you're not adverse to some javascript. i've just implemented javascript configs. using javascript configs, you can check the hostname with the shell method.

var hostname = slate.shell("/bin/hostname", true);
if (hostname === "macbookpro-13") {
  // create the layout for 13''
} else if (hostname === "macbookpro-15") {
  // create the layout for 15''
}
Jigish Patel jigish closed this
Bradley Wright

I was literally just looking at that.

Question: how do I see the output of slate.log?

Otherwise I think the new config solves this for me. :+1:

Jigish Patel
Owner

slate.log is only visible when running slate in debug mode. you can do that by cloning the repo and using the Slate.app in build/Debug/Slate.app (there may be some permissions errors that you need to sort out) or running Slate in Xcode.

Jigish Patel
Owner

another way to quickly see what is going on is to throw an exception in the javascript instead of using slate.log. the exception will bubble up and cause an alert to be shown with the message of the exception in the alert.

Jigish Patel
Owner

since I haven't completely documented the JavaScript stuff, here is an example of layouts:

// hideAdium, focusITerm, topLeft, and topRight are operation objects that are declared above.
var layout = S.lay("myLayout", {
  "before" : { "operations" : hideAdium },
  "after" : { "operations" : focusITerm },
  "MacVim" : {
    "repeat" : true,
    "ignore-fail" : true,
    "operations" : [topLeft, function(win) { S.log("IN TOP RIGHT: "+win.title()); win.doOperation(topRight); }]
  },
  "Xcode" : {
    "repeat" : true,
    "ignore-fail" : true,
    "operations" : main
  }
});
var myLayout = S.op("layout", { "name" : layout });
S.bind("1:ctrl", myLayout);
S.cfg("checkDefaultsOnLoad", "true");
S.def(["1440x900"], layout);

The other option is to create the layouts in the normal config and use the if to just set the default using something like:

if (hostname === "macbookpro-13") {
  S.def(["1440x900"], "mbp-13-layout-name");
} else if (hostname === "macbookpro-15") {
  S.def(["1440x900"], "mbp-15-layout-name");
}
Bradley Wright

For the record: /bin/hostname comes back with a line break attached, so you actually want:

var hostname = slate.shell('/bin/hostname', true).trim();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.