我从Iterm2官方网站获得了这个bash脚本。printf "\e]1337;SetBadgeFormat=%s\a" $(echo "text" | base64)
我像波纹管一样尝试了exec,没有错误,但是无法设置iterm2徽章
var exec = require('child_process').exec;
exec('printf "\e]1337;SetBadgeFormat=%s\a" $(echo "text" | base64)');
最佳答案
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);
});