Пример #1
0
function generateEndpoints($force = FALSE)
{
    global $bundle;
    $HOME = exec('echo $HOME');
    $data = "{$HOME}/Library/Application Support/Alfred 2/Workflow Data/{$bundle}";
    if (!file_exists("{$data}/endpoints") && is_dir("{$data}/endpoints")) {
        mkdir("{$data}/endpoints");
    }
    if (!(file_exists("{$data}/endpoints/endpoints.json") && file_exists("{$data}/endpoints/endpoints.list")) || filemtime("{$data}/endpoints/endpoints.json") < filemtime(dirname(__DIR__)) || $force !== FALSE) {
        // Okay, we need to update the files.
        $dirs = array_diff(scandir(dirname(__DIR__)), array('.', '..', '.git', '.DS_Store'));
        if (file_exists("{$data}/endpoints/endpoints.list")) {
            unlink("{$data}/endpoints/endpoints.list");
        }
        $fp = fopen("{$data}/endpoints/endpoints.list", 'w');
        $me = basename(__DIR__);
        foreach ($dirs as $d) {
            $d = str_replace('//', '/', str_replace($me, '', __DIR__) . "/{$d}");
            $bundle = readPlistValue('bundleid', "{$d}/info.plist");
            if (empty($bundle)) {
                continue;
            }
            $endpoints[$bundle] = $d;
            fwrite($fp, "\"{$bundle}\"=\"{$d}\"\n");
        }
        file_put_contents("{$data}/endpoints/endpoints.json", utf8_encode(json_encode($endpoints)));
        fclose($fp);
    } else {
        return FALSE;
    }
}
Пример #2
0
function getWorkflowData($dir)
{
    $plist = "{$dir}/info.plist";
    if (!file_exists($plist)) {
        return FALSE;
    }
    $bundle = utf8_encode(trim(readPlistValue('bundleid', $plist)));
    if (!$bundle) {
        return FALSE;
    }
    // Get the Workflow name
    $name = utf8_encode(trim(readPlistValue('name', $plist)));
    // Get the author
    $author = utf8_encode(trim(readPlistValue('createdby', $plist)));
    // Figure out if it's disabled.
    $disabled = utf8_encode(readPlistValue('disabled', $plist));
    // Strangely, sometimes these weren't set on my computer, so, well, that's strange.
    // My guess is that they were older workflows, so maybe the problems was older plist
    // structures from way-back Alfred 2.
    if (empty($disabled)) {
        $disabled = 'TRUE';
    }
    $disabled = strtoupper($disabled);
    if (file_exists($dir . '/packal/package.xml')) {
        $packal = 'TRUE';
    } else {
        $packal = 'FALSE';
    }
    return array('name' => $name, 'bundle' => $bundle, 'author' => $author, 'disabled' => $disabled, 'packal' => $packal);
}