如何执行脚本以从Node.js设置iterm2徽章? [英] How to exec script to set iterm2 Badge from nodejs?

查看:230
本文介绍了如何执行脚本以从Node.js设置iterm2徽章?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从Iterm2官方网站上获得了这个bash脚本.

I get this bash script from Iterm2 official site.

printf "\e]1337;SetBadgeFormat=%s\a" $(echo "text" | base64)

我像波纹管一样尝试了exec,没有错误,但是无法设置iterm2徽章

I tried exec like bellow, there is no error, but failed to set iterm2 Badge

var exec = require('child_process').exec;
exec('printf "\e]1337;SetBadgeFormat=%s\a" $(echo "text" | base64)');

推荐答案

setBadgeFormat.js =>

setBadgeFormat.js =>

#!/usr/bin/env node

var rawBadgeFormat = 'test'
var base64BadgeFormat = new Buffer(rawBadgeFormat).toString('base64')
var setBadgeFormatCmd = 'printf "\\e]1337;SetBadgeFormat=' + base64BadgeFormat + '\\a"'
require('child_process').exec(setBadgeFormatCmd, function(error, stdout, stderr) {
    if (error) console.log(error);
    process.stdout.write(stdout); // this line actually do the trick
    process.stderr.write(stderr);
});

这篇关于如何执行脚本以从Node.js设置iterm2徽章?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆