How to use the alfy.input function in alfy

To help you get started, we’ve selected a few alfy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github importre / alfred-slack-status / update.js View on Github external
'use strict';
const alfy = require('alfy');
const got = require('got');
const Rx = require('rxjs/Rx');
const utils = require('./utils');

const idx = parseInt(alfy.input, 10);
const status = idx < 0 ? alfy.config.get('custom') : utils.makeOutput()[idx];
const title = status.title === utils.REMOVE_STATUS ? '' : status.title;
const tokens = alfy.config.get('tokens') || {};
const sources = Object.keys(tokens).map(key => {
	const baseUrl = 'https://slack.com/api/users.profile.set';
	const options = {
		method: 'get',
		query: {
			/* eslint camelcase: ["error", {properties: "never"}] */
			token: tokens[key],
			profile: JSON.stringify({
				status_text: title,
				status_emoji: status.emoji
			})
		}
	};
github xfslove / alfred-google-translate / index.js View on Github external
doTranslate({
            text: alfy.input,
            from: {
                language: 'auto',
                ttsfile: os.tmpdir() + '/' + uuidv4() + ".mp3"
            },
            to: {
                language: 'en',
                ttsfile: os.tmpdir() + '/' + uuidv4() + ".mp3"
            }
        });
        return;
    }
    // language detect
    translator
        .translate(alfy.input, {
            from: 'auto',
            to: 'en',
            domain: g_config.domain,
            client: 'gtx'
        })
        .then(function (res) {
            var detect = res.from.language.iso;
            var from = 'auto';
            var to = 'en';
            if (pair0 === detect) {
                from = pair0;
                to = pair1;
            } else if (pair1 === detect) {
                from = pair1;
                to = pair0;
            }
github jukben / alfred-emoji / index.js View on Github external
if (!results.length) {
        results = nothingFound; 
      }

      return results;
  }

  if (ALWAYS_OFFLINE) {
    return alfy.output(getOfflineEmoji());
  }

  return alfy
    .fetch("emoji.getdango.com/api/emoji", {
      maxAge: 8640000000, // cache for 24 hours
      query: {
        q: alfy.input,
        syn: 1
      }
    })
    .then(({ results, synonyms = [] } = {}) => {
      if (!results) {
        return alfy.output(nothingFound);
      }

      return alfy.output([...new Set([...synonyms, ...results.map(({ text }) => text)])].map(format));
    })
    .catch(() => {
      alfy.output(getOfflineEmoji())
    });
};
github jeppestaerk / alfred-show-network-info / index.js View on Github external
}
		},
		icon: {
			path: `icons/${type}.png`
		},
		text: {
			copy: ip,
			largetype: ip
		},
		variables: {
			action: 'copy'
		}
	})
}

if (alfy.input.split(" ")[0].toLowerCase() === 'ssh') {
	addOutput(`Type ssh username for ${alfy.input.split(" ")[1]}`, `ssh ${alfy.input.split(" ")[2] || 'root'}@${alfy.input.split(" ")[1]}`, `ssh ${alfy.input.split(" ")[2] || 'root'}@${alfy.input.split(" ")[1]}`, 'Public', 'ssh')
} else if (alfy.input.toLowerCase() === 'scan') {
	promises.push(localDevices().then(devices => devices.forEach(device => addIPOutput('Device', device.ip, device.name, device.mac))).catch(() => addIPOutput('No local devices found', 'Local')));
} else if (alfy.input.toLowerCase() === 'ipv6') {
	if (process.env['show_public'] === 'true') promises.push(publicIp.v6().then(ip => addIPOutput('Public', ip, '', '')).catch(() => addIPOutput('Public', 'IPv6 not found', '', '')));
	if (process.env['show_local'] === 'true') promises.push(internalIp.v6().then(ip => addIPOutput('Internal', ip, '', '')).catch(() => addIPOutput('Internal', 'IPv6 not found', '', '')));
	if (process.env['show_gateway'] === 'true') promises.push(defaultGateway.v6().then(ip => addIPOutput('Gateway', ip.gateway, '', '')).catch(() => addIPOutput('Gateway', 'IPv6 not found', '', '')));
} else {
	if (process.env['show_public'] === 'true') promises.push(publicIp.v4().then(ip => addIPOutput('Public', ip, '', '')).catch(() => addIPOutput('Public', 'IPv4 not found', '', '')));
	if (process.env['show_local'] === 'true') promises.push(internalIp.v4().then(ip => addIPOutput('Internal', ip, '', '')).catch(() => addIPOutput('Internal', 'IPv4 not found', '', '')));
	if (process.env['show_gateway'] === 'true') promises.push(defaultGateway.v4().then(ip => addIPOutput('Gateway', ip.gateway, '', '')).catch(() => addIPOutput('Gateway', 'IPv4 not found', '', '')));
}

Promise.all(promises).then(() => {
	if (!alfy.input) {
		if (process.env['show_scan'] === 'true') addOutput('Discover devices on local network', '', `${process.env['keyword']} scan`, 'Scan', 'rerun');
github prashantpalikhe / alfred-bundlephobia / index.js View on Github external
async function main() {
	try {
		const { name, version, gzip, size } = await getPackageStats(alfy.input);

		alfy.output([
			{
				title: `${name}@${version}`,
				subtitle: `Size: ${formatBytes(size)}, Gzip: ${formatBytes(
					gzip
				)}`,
				arg: `https://bundlephobia.com/result?p=${name}@${version}`,
				quicklookurl: `https://bundlephobia.com/result?p=${name}@${version}`
			}
		]);
	} catch (e) {
		alfy.error(e.message);
	}
}
github CoderMageFox / alfredMagic / MDN / MDN.js View on Github external
(function () {
    FeachMDN.feachMDNResult(alfy.input);
})();
github anoff / alfred-github / index.js View on Github external
'use strict';
const alfy = require('alfy');

alfy.fetch('https://api.github.com/search/repositories', {
	query: {
		q: alfy.input
	},
	maxAge: 10 * 60 * 1000
}).then(data => {
	const items = data.items
		.map(elm => ({
			title: elm.full_name,
			subtitle: elm.description,
			arg: elm.html_url
		}));
	alfy.output(items);
});
github importre / alfred-hl / src / theme.js View on Github external
const fs = require('fs');
const alfy = require('alfy');

const input = alfy.input.toLowerCase();
const themeDir = './node_modules/highlight.js/styles/';

function comp(a, b) {
  const i = a.toLowerCase().indexOf(input);
  const j = b.toLowerCase().indexOf(input);
  if (i >= 0 && j >= 0) {
    if (i - j === 0) return a.length - b.length;
    return i - j;
  }
  if (i >= 0) return -1;
  if (j >= 0) return 1;
  return a.localeCompare(b);
}

const output = fs
  .readdirSync(themeDir)
github nicklayb / alfred-bitbucket / saveUsername.js View on Github external
const alfy = require('alfy');
const setDefaultUsername = require('./config').setDefaultUsername;

setDefaultUsername(alfy.input);
github xfslove / alfred-google-translate / index.js View on Github external
.then(function (res) {
            var detect = res.from.language.iso;
            var from = 'auto';
            var to = 'en';
            if (pair0 === detect) {
                from = pair0;
                to = pair1;
            } else if (pair1 === detect) {
                from = pair1;
                to = pair0;
            }

            doTranslate({
                text: alfy.input,
                from: {
                    language: from,
                    ttsfile: os.tmpdir() + '/' + uuidv4() + ".mp3"
                },
                to: {
                    language: to,
                    ttsfile: os.tmpdir() + '/' + uuidv4() + ".mp3"
                }
            });
        });