-
Notifications
You must be signed in to change notification settings - Fork 0
/
left.js
136 lines (132 loc) · 4.45 KB
/
left.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
'use strict';
var Direction;
(function (Direction) {
Direction[Direction["LEFT"] = 0] = "LEFT";
Direction[Direction["RIGHT"] = 1] = "RIGHT";
})(Direction || (Direction = {}));
function writeTextToFile(text, filePath, overwriteExistingContent) {
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var path = Path(filePath.toString());
try {
var openedFile = app.openForAccess(path, {
writePermission: true
});
if (overwriteExistingContent) {
app.setEof(openedFile, { to: 0 });
}
app.write(text, { to: openedFile, startingAt: app.getEof(openedFile) });
app.closeAccess(openedFile);
return true;
}
catch (error) {
try {
app.closeAccess(path);
}
catch (error) {
console.log("Couldn't close file: ".concat(error));
}
return false;
}
}
function readFile(filePath) {
var app = Application.currentApplication();
app.includeStandardAdditions = true;
var path = Path(filePath.toString());
return app.read(path);
}
var CacheObject = /** @class */ (function () {
function CacheObject(cacheFilePath) {
this.cacheFilePath = cacheFilePath;
this.stateObject = JSON.parse(readFile(cacheFilePath));
this.currentState = undefined;
return this;
}
CacheObject.prototype.getState = function (stateName) {
this.currentState = this.stateObject[stateName];
this.stateObject[stateName] = this.currentState;
return this.currentState;
};
CacheObject.prototype.write = function (stateName, stateValue) {
this.stateObject[stateName] = stateValue;
return this;
};
CacheObject.prototype.save = function () {
writeTextToFile(JSON.stringify(this.stateObject), this.cacheFilePath, true);
return this;
};
return CacheObject;
}());
var advanceState = function (cacheObject, toggleKey, states, direction) {
var _a;
if (direction === void 0) { direction = Direction.LEFT; }
var btt = Application("BetterTouchTool");
var currentState = parseInt((_a = cacheObject.getState(toggleKey)) !== null && _a !== void 0 ? _a : "0");
var newState = (function () {
switch (direction) {
case Direction.LEFT:
return currentState + states.length - 1;
case Direction.RIGHT:
return currentState + 1;
}
})() % states.length;
btt.trigger_action(JSON.stringify(states[newState]));
cacheObject.write(toggleKey, newState.toString()).save();
return cacheObject;
};
var oneThirdsStates = [
{
BTTTriggerType: -1,
BTTTriggerTypeDescription: "Please Select a Trigger ",
BTTTriggerClass: "BTTTriggerTypeOtherTriggers",
BTTPredefinedActionType: 108,
BTTPredefinedActionName: "Resize window to Left Third",
BTTEnabled2: 1,
BTTAlternateModifierKeys: 0,
BTTUUID: "5511861E-8666-4566-B7BE-AAD91F2BD108",
BTTEnabled: 1,
BTTModifierMode: 0,
BTTOrder: 1,
BTTDisplayOrder: 0,
BTTMergeIntoTouchBarGroups: 0
},
{
BTTTriggerType: -1,
BTTTriggerTypeDescription: "Please Select a Trigger ",
BTTTriggerClass: "BTTTriggerTypeOtherTriggers",
BTTPredefinedActionType: 109,
BTTPredefinedActionName: "Resize window to Middle Third",
BTTEnabled2: 1,
BTTAlternateModifierKeys: 0,
BTTUUID: "D93C495B-09D3-43F7-9D11-9DACF51BA2F4",
BTTEnabled: 1,
BTTModifierMode: 0,
BTTOrder: 2,
BTTDisplayOrder: 0,
BTTMergeIntoTouchBarGroups: 0
},
{
BTTTriggerType: -1,
BTTTriggerTypeDescription: "Please Select a Trigger ",
BTTTriggerClass: "BTTTriggerTypeOtherTriggers",
BTTPredefinedActionType: 110,
BTTPredefinedActionName: "Resize window to Right Third",
BTTEnabled2: 1,
BTTAlternateModifierKeys: 0,
BTTUUID: "020D20AA-5560-4ACE-A1DF-E51A48873BC9",
BTTEnabled: 1,
BTTModifierMode: 0,
BTTOrder: 3,
BTTDisplayOrder: 0,
BTTMergeIntoTouchBarGroups: 0
}
];
var cacheFilePath = "/tmp/betterTouchTool.json";
var cacheObject = new CacheObject(cacheFilePath);
var oneThirds = function (direction) {
var toggleKey = "oneThirds";
advanceState(cacheObject, toggleKey, oneThirdsStates, direction);
};
oneThirds(Direction.LEFT);
//@ts-ignore
returnToBTT("Done");