-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
40 lines (30 loc) · 947 Bytes
/
index.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
#! /usr/bin/env node
import { exec } from "child_process";
const TIMEZONES = ["Europe/London", "America/Toronto"];
function cmd(command) {
return new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
return reject(error);
}
if (stderr) {
return reject(stderr);
}
return resolve(stdout);
});
});
}
let user = await cmd("whoami");
user = user.trim();
if (user !== "root") {
console.log("Timeshift needs root privileges. Please run again with sudo.");
process.exit(1);
}
let currentTimezone = await cmd("systemsetup -gettimezone");
currentTimezone = currentTimezone.split(": ")[1].trim();
const currentIndex = TIMEZONES.indexOf(currentTimezone);
const newIndex = currentIndex < TIMEZONES.length - 1 ? currentIndex + 1 : 0;
const newTimezone = TIMEZONES[newIndex];
try {
await cmd("systemsetup -settimezone " + newTimezone);
} catch (e) {}