macos-defaults/record/dock/show-recents/false.js

51 lines
1.4 KiB
JavaScript
Raw Normal View History

2022-08-18 11:57:18 +00:00
const MacRunner = require('../../mac-runner')
const { compressPngImage } = require('../../utils')
module.exports = {
run: async (outputPath) => {
console.log('> Recording dock show-recents with param set to false')
2022-08-18 11:57:18 +00:00
try {
const { screenWidth, screenHeight } = MacRunner.getScreenSize()
// Dock gets larger when not showing most recent Apps
const dockHeight = MacRunner.getDockHeight() + 4
2022-08-18 11:57:18 +00:00
const runner = new MacRunner()
await runner
.setDefault('com.apple.dock', 'show-recents', '-bool false', '0')
.killApp('Dock')
.wait(1000)
.captureScreenRect(
screenWidth - 740,
screenHeight - dockHeight,
740,
dockHeight,
`${outputPath}/false-tmp.png`
)
.deleteDefault('com.apple.dock', 'show-recents')
.killApp('Dock')
.run()
} catch (runnerError) {
logRollbackInfo()
2022-08-18 11:57:18 +00:00
throw new Error(runnerError)
}
try {
2022-08-18 11:57:18 +00:00
await compressPngImage(`${outputPath}/false-tmp.png`, outputPath, 'false')
} catch (compressPngImageError) {
logRollbackInfo()
throw new Error(compressPngImageError)
}
return { filepath: `${outputPath}/false` }
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.dock show-recents && killall Dock')
}