قالب وردپرس درنا توس
Home / Mac / Build an Automator script to get Windows into position

Build an Automator script to get Windows into position



If you want to accurately position your application windows without using any third party tools, you can build a versatile script in Automator to attach windows to parts of your screen. You can give you more options like left third, right two-thirds, corners or anything you can bring. Then you can put the workflow into the Services menu, where you can quickly trigger it with a hotkey. The framework of this JavaScript / JXA script can be used to develop your own customizable window organizing tool.




Here is the final script:

 function operation (input, parameters) {

app = Application.currentApplication ();
app.includeStandardAdditions = true;

was frontAppName = Program ("System Events"). processes. hence ({frontmost: {& # 39; = & # 39 ;: true}}) [0] .name ();
var frontApp = Program (frontAppName);

var areaChoices = ["Left Third", "Right Two-Thirds", "Top Left Corner"];
var area = app.chooseFromList (areaChoices, {withPrompt: "Where?"});

was displayText = app.doShellScript ("/ usr / sbin / system_profiler SPDisplaysDataType");
was displayInfo = displayText.split ("UI looks like:");

for (was info of displayInfo) {
if (info.indexOf ("Main Display: Yes")> -1) {
var infoPieces = info.split ("");
displayWidth = infoPieces [0];
displayHeight = infoPieces [2];
break;
}
}

if (range == "left third") {
frontApp.windows [0] .bounds = {x: 0, y: 0, width: displayWidth * .3333, height: displayHeight};
} other if (area == "Right two thirds") {
frontApp.windows [0] .bounds = {x: displayWidth * .3333, y: 0, width: displayWidth * .6667, height: displayHeight};
}
} 

Source link