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

76 lines
2.2 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) => {
2020-11-27 12:45:16 +00:00
console.log(
'> Recording menu bar clock FlashDateSeparators with param set to false'
)
// Set the menu bar menuExtras to only show the clock, it will be on the left of notification center, siri, and spotlight search.
2020-11-27 12:45:16 +00:00
const { stderr: setEnvError } = await exec(
`defaults write com.apple.menuextra.clock FlashDateSeparators -bool false && killall SystemUIServer && sleep 10`
)
if (setEnvError) {
2020-11-27 12:45:16 +00:00
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 = 29
const cropArea = {
2020-11-27 12:45:16 +00:00
x: width - recordWidth,
y: height - recordHeight, // Film the menu bar, which is 29 pixels
2020-11-27 12:45:16 +00:00
width: recordWidth,
height: recordHeight,
}
// Action!
await aperture.startRecording({ cropArea })
await delay(2000)
const fp = await aperture.stopRecording()
// End recording
try {
await compressVideo(fp, outputPath, 'false')
} catch (compressVideoError) {
logRollbackInfo()
throw new Error(compressVideoError)
}
2020-11-27 12:45:16 +00:00
const { stderr: deleteEnvError } = await exec(
'defaults delete com.apple.menuextra.clock FlashDateSeparators && killall SystemUIServer && sleep 10'
)
if (deleteEnvError) {
2020-11-27 12:45:16 +00:00
console.error(
'An error occured while cleaning the menu bar clock FlashDateSeparators environment'
)
logRollbackInfo()
throw new Error(deleteEnvError)
}
return { filepath: `${outputPath}/false`, isVideo: true }
2020-11-27 12:45:16 +00:00
},
}
function logRollbackInfo() {
2020-11-27 12:45:16 +00:00
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'
)
}