macos-defaults/record/menubar/FlashDateSeparators/true.js

60 lines
2.1 KiB
JavaScript
Raw Normal View History

const aperture = require('aperture')()
const delay = require('delay')
const robot = require('robotjs')
const util = require('util')
const exec = util.promisify(require('child_process').exec)
const { makeAppActive, compressVideo } = require('../../utils')
module.exports = {
run: async (outputPath) => {
console.log('> Recording menu bar clock FlashDateSeparators with param set to true')
// Set the menu bar menuExtras to only show the clock, it will be on the left of notification center, siri, and spotlight search.
const { stderr: setEnvError } = await exec(`defaults write com.apple.menuextra.clock FlashDateSeparators -bool true && killall SystemUIServer && sleep 10`)
if (setEnvError) {
console.error('An error occured while setting up the menu bar clock FlashDateSeparators command')
logRollbackInfo()
throw new Error(setEnvError)
}
// Preparation
await makeAppActive('Finder')
const { width, height } = robot.getScreenSize()
const recordWidth = 400
const recordHeight = 22
const cropArea = {
x: width - recordWidth, y: height - recordHeight, // Film the menu bar, which is 22 pixels
width: recordWidth, height: recordHeight
}
// Action!
await aperture.startRecording({ cropArea })
await delay(2000)
const fp = await aperture.stopRecording()
// End recording
try {
await compressVideo(fp, outputPath, 'true')
} catch (compressVideoError) {
logRollbackInfo()
throw new Error(compressVideoError)
}
2020-11-23 20:37:13 +00:00
const { stderr: deleteEnvError } = await exec('defaults delete com.apple.menuextra.clock FlashDateSeparators && killall SystemUIServer && sleep 10')
if (deleteEnvError) {
console.error('An error occured while cleaning the menu bar clock FlashDateSeparators environment')
logRollbackInfo()
throw new Error(deleteEnvError)
}
return { filepath: `${outputPath}/true`, isVideo: true }
}
}
function logRollbackInfo() {
console.info('Please manually run this command to make sure everything is properly reset:')
console.info('defaults delete com.apple.menuextra.clock FlashDateSeparators && killall SystemUIServer')
}