-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunc.php
58 lines (52 loc) · 1.85 KB
/
func.php
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
<?php
function getTZ()
{
$tzf = getenv('localTimezone');
if (!$tzf) {
$tzf = readlink('/etc/localtime');
$tzf = substr($tzf, strpos($tzf, '/zoneinfo/') + 10);
// setConf('localTimezone', $tzf);
// We could save this with setConf, but it would create a problem for those who travel between timezones a lot
}
return $tzf;
}
function findNode()
{
$node = shell_exec("/usr/bin/which node");
if (!$node || substr($node, 0, 1) != "/") return false;
return trim($node);
}
function getLocale($node, $default)
{
$l = getenv('locale');
if ($l) return $l;
$l = strtolower(preg_replace("/[^A-Za-z\-]/", "",
shell_exec('langs=(`defaults read NSGlobalDomain AppleLanguages`); echo ${langs[1]/,/}')));
$supported = shell_exec("$node list-locales.js");
$supported = json_decode($supported);
if (json_last_error() !== JSON_ERROR_NONE || !in_array($l, $supported->list)) return $default;
setConf('locale', $l);
return $l;
}
function setConf($var, $val, $remove = false)
{
shell_exec('/usr/bin/osascript -e \'tell application id "com.runningwithcrayons.Alfred" to ' .
($remove ? 'remove' : 'set') . ' configuration "' . $var . '"' . (!$remove ? ' to value "' . $val . '"' : '') .
' in workflow "com.hilbertgilbertson.whencord" with exportable\'');
}
function listItem($title, $subtitle = null, $arg = false, $valid = true, $icon = null, $launch = false)
{
$item = [
'valid' => $valid,
'title' => (string)$title
];
if ($subtitle) $item['subtitle'] = (string)$subtitle;
if ($arg !== false) $item['arg'] = (string)$arg;
if ($icon) $item['icon'] = is_array($icon) ? $icon : ['path' => "icons/$icon.png"];
if ($launch) $item['variables']['launch'] = $launch;
return $item;
}
function listError($items)
{
die(json_encode(['items' => $items]));
}