mirror of
https://github.com/yannbertrand/macos-defaults
synced 2024-12-12 12:42:32 +00:00
78d713f8ab
* ⬆️ Upgrade prettier to v3 * 🚨 Run prettier v3 --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Yann Bertrand <5855339+yannbertrand@users.noreply.github.com>
62 lines
1.8 KiB
JavaScript
62 lines
1.8 KiB
JavaScript
const MacRunner = require('../../mac-runner')
|
|
const util = require('util')
|
|
const exec = util.promisify(require('child_process').exec)
|
|
const { compressPngImage } = require('../../utils')
|
|
|
|
module.exports = {
|
|
run: async (outputPath) => {
|
|
console.log('> Recording TextEdit opens rich text files to true')
|
|
|
|
try {
|
|
const fileName = '/tmp/lorem.txt'
|
|
await manageFile(fileName, true)
|
|
await addContentToFile(fileName, '')
|
|
|
|
const runner = new MacRunner()
|
|
await runner
|
|
.setDefault('com.apple.TextEdit', 'RichText', '-bool false', '0')
|
|
.openApp('TextEdit', fileName)
|
|
.moveAndResizeApp('TextEdit', 0, 0, 740, 400)
|
|
.captureApp('TextEdit', `${outputPath}/false.png`)
|
|
.deleteDefault('com.apple.TextEdit', 'RichText')
|
|
.killApp('TextEdit')
|
|
.run()
|
|
|
|
await manageFile(fileName, false)
|
|
} catch (runnerError) {
|
|
throw new Error(runnerError)
|
|
}
|
|
|
|
try {
|
|
await compressPngImage(`${outputPath}/false.png`, outputPath, 'false')
|
|
} catch (compressPngImageError) {
|
|
throw new Error(compressPngImageError)
|
|
}
|
|
|
|
return { filepath: `${outputPath}/false` }
|
|
},
|
|
}
|
|
|
|
async function manageFile(filename, create) {
|
|
console.log(` Command: ${create ? 'create' : 'remove'} ${filename}`)
|
|
const { stderr: mngFile } = await exec(
|
|
`${create ? 'touch' : 'rm -f'} ${filename}`,
|
|
)
|
|
if (mngFile) {
|
|
console.error('An error occured while working with a file')
|
|
throw new Error(mngFile)
|
|
}
|
|
}
|
|
|
|
async function addContentToFile(filename, content) {
|
|
console.log(` Command: add content to ${filename}`)
|
|
const { stderr: mngFile } = await exec(
|
|
`cat > ${filename} << EOF
|
|
${content}
|
|
EOF`,
|
|
)
|
|
if (mngFile) {
|
|
console.error('An error occured while working with a file')
|
|
throw new Error(mngFile)
|
|
}
|
|
}
|