How to exec script to set iterm2 Badge from nodejs?

泄露秘密 提交于 2020-01-24 13:40:21

问题


I get this bash script from Iterm2 official site.

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

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)');

回答1:


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);
});


来源:https://stackoverflow.com/questions/36613285/how-to-exec-script-to-set-iterm2-badge-from-nodejs

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!