├── hyperalfred.gif ├── yarn.lock ├── package.json ├── LICENSE ├── .gitignore ├── README.md └── index.js /hyperalfred.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gjuchault/hyperalfred/HEAD/hyperalfred.gif -------------------------------------------------------------------------------- /yarn.lock: -------------------------------------------------------------------------------- 1 | # THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. 2 | # yarn lockfile v1 3 | 4 | 5 | graceful-fs@^4.1.11: 6 | version "4.1.11" 7 | resolved "https://registry.yarnpkg.com/graceful-fs/-/graceful-fs-4.1.11.tgz#0e8bdfe4d1ddb8854d64e04ea7c00e2a026e5658" 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "hyperalfred", 3 | "version": "0.1.1", 4 | "description": "Open hyper with alfred commands", 5 | "main": "index.js", 6 | "keywords": [ 7 | "hyper", 8 | "alfred" 9 | ], 10 | "repository": "https://github.com/gjuchault/hyperalfred.git", 11 | "author": "Gabriel Juchault ", 12 | "license": "MIT", 13 | "homepage": "https://github.com/gjuchault/hyperalfred#readme", 14 | "dependencies": { 15 | "graceful-fs": "^4.1.11" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Gabriel JUCHAULT 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | 8 | # Runtime data 9 | pids 10 | *.pid 11 | *.seed 12 | *.pid.lock 13 | 14 | # Directory for instrumented libs generated by jscoverage/JSCover 15 | lib-cov 16 | 17 | # Coverage directory used by tools like istanbul 18 | coverage 19 | 20 | # nyc test coverage 21 | .nyc_output 22 | 23 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 24 | .grunt 25 | 26 | # Bower dependency directory (https://bower.io/) 27 | bower_components 28 | 29 | # node-waf configuration 30 | .lock-wscript 31 | 32 | # Compiled binary addons (https://nodejs.org/api/addons.html) 33 | build/Release 34 | 35 | # Dependency directories 36 | node_modules/ 37 | jspm_packages/ 38 | 39 | # TypeScript v1 declaration files 40 | typings/ 41 | 42 | # Optional npm cache directory 43 | .npm 44 | 45 | # Optional eslint cache 46 | .eslintcache 47 | 48 | # Optional REPL history 49 | .node_repl_history 50 | 51 | # Output of 'npm pack' 52 | *.tgz 53 | 54 | # Yarn Integrity file 55 | .yarn-integrity 56 | 57 | # dotenv environment variables file 58 | .env 59 | 60 | # next.js build output 61 | .next 62 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # hyperalfred 2 | 3 | ⚡🔎🎩 Makes Alfred works with Hyper terminal 4 | 5 | ![hyperalfred](https://raw.githubusercontent.com/gjuchault/hyperalfred/master/hyperalfred.gif) 6 | 7 | ## Installation 8 | 9 | ### Hyper plugin 10 | 11 | Using Hyper, you can simply use `hyper`: 12 | 13 | ``` 14 | hyper i hyperalfred 15 | ``` 16 | 17 | ### Alfred script 18 | 19 | Open Alfred Preferences, go to « Features », « Terminal / Shell ». 20 | Select « Custom » as Application, and paste the following (replace `USERNAME` with your actual username): 21 | 22 | ```applescript 23 | on alfred_script(q) 24 | write_to_file(q, "/Users/USERNAME/.hyper_plugins/hyperalfred.txt", false) 25 | tell application "Hyper" to activate 26 | end alfred_script 27 | 28 | on write_to_file(this_data, target_file, append_data) 29 | try 30 | tell application "System Events" to exists file target_file 31 | if not the result then do shell script "> " & quoted form of target_file 32 | set the open_target_file to open for access target_file with write permission 33 | if append_data is false then set eof of the open_target_file to 0 34 | write this_data to the open_target_file starting at eof 35 | close access the open_target_file 36 | return true 37 | on error e 38 | try 39 | display dialog e 40 | close access target_file 41 | end try 42 | return false 43 | end try 44 | end write_to_file 45 | ``` 46 | 47 | If you do not know what username you should use, open a Terminal and run `whoami` or `id -un` 48 | 49 | You're ready to go ! 50 | 51 | ## How it works 52 | 53 | As you may know, Electron apps are known to be not working with Apple Script. I'm using a buffer file (located in `~/.hyper_plugins/hyperalfred.txt`) 54 | Once the plugin is loaded on Hyper, it checks that file for a command. If there is one, it just write it using Hyper API and clears the file. 55 | 56 | ## Caveats 57 | 58 | hyperalfred will only work if Hyper is **not** already the focused application. 59 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const fs = require('graceful-fs') 2 | const { promisify } = require('util') 3 | const { resolve } = require('path') 4 | const { homedir } = require('os') 5 | 6 | const readFile = promisify(fs.readFile) 7 | const writeFile = promisify(fs.writeFile) 8 | const access = promisify(fs.access) 9 | 10 | const commandFile = resolve(homedir(), '.hyper_plugins', 'hyperalfred.txt') 11 | 12 | async function loadCommand() { 13 | try { 14 | const hasCommand = await access(commandFile, fs.constants.R_OK | fs.constants.W_OK) 15 | 16 | let command = await readFile(commandFile, 'utf8') 17 | 18 | command = command.trim() 19 | 20 | if (command.length === 0) { 21 | return null 22 | } 23 | 24 | return command 25 | } catch (err) { 26 | if (err.code === 'ENOENT') { 27 | console.log('[hyperalfred] command file not existing, ignoring') 28 | } 29 | 30 | console.error(err) 31 | } 32 | } 33 | 34 | async function sendCommand(session, command) { 35 | console.log(`[hyperalfred] sending command ${command} to window`) 36 | 37 | if (session && typeof session.write === 'function') { 38 | session.write(command) 39 | session.write('\n') 40 | } 41 | } 42 | 43 | async function clearCommand() { 44 | try { 45 | await writeFile(commandFile, '') 46 | } catch (err) { 47 | console.error(err) 48 | } 49 | } 50 | 51 | async function main(session) { 52 | const command = await loadCommand() 53 | 54 | if (!command) { 55 | console.log('[hyperalfred] no command found') 56 | return 57 | } 58 | 59 | console.log(`[hyperalfred] command found : ${command}`) 60 | 61 | await sendCommand(session, command) 62 | await clearCommand() 63 | } 64 | 65 | exports.onWindow = win => { 66 | win.rpc.on('hyperalfred write command', async (sessionId) => { 67 | let session = win.sessions.get(sessionId) 68 | 69 | await main(session) 70 | }) 71 | } 72 | 73 | exports.middleware = (store) => (next) => (action) => { 74 | if ('SESSION_ADD' === action.type || 'SESSION_SET_ACTIVE' === action.type) { 75 | const sessionId = action.uid 76 | 77 | setTimeout(() => rpc.emit('hyperalfred write command', sessionId), 200) 78 | 79 | next(action); 80 | } else { 81 | next(action); 82 | } 83 | } --------------------------------------------------------------------------------