mirror of
https://github.com/yannbertrand/macos-defaults
synced 2024-12-16 22:43:08 +00:00
49 lines
1.8 KiB
JavaScript
49 lines
1.8 KiB
JavaScript
const delay = require('delay')
|
|
const glob = require('glob-promise')
|
|
const robot = require('robotjs')
|
|
const util = require('util')
|
|
const exec = util.promisify(require('child_process').exec)
|
|
const { compressPngImage } = require('../../utils')
|
|
|
|
module.exports = {
|
|
run: async (outputPath) => {
|
|
console.log('> Recording dock orientation with param set to bottom')
|
|
|
|
const { stderr: setEnvError } = await exec('defaults write com.apple.screencapture show-thumbnail -bool false && defaults write com.apple.dock orientation -string bottom && killall Dock')
|
|
if (setEnvError) {
|
|
console.error('An error occured while setting up the dock orientation command')
|
|
logRollbackInfo()
|
|
throw new Error(setEnvError)
|
|
}
|
|
|
|
// Preparation
|
|
await delay(3000)
|
|
|
|
// Screenshot
|
|
robot.keyTap('3', ['command', 'shift'])
|
|
|
|
await delay(1000)
|
|
const screenshot = (await glob(`/Users/${process.env.USER}/Desktop/*.png`)).pop()
|
|
|
|
try {
|
|
await compressPngImage(screenshot, outputPath, 'bottom')
|
|
} catch (compressPngImageError) {
|
|
logRollbackInfo()
|
|
throw new Error(compressPngImageError)
|
|
}
|
|
|
|
const { stderr: deleteEnvError } = await exec('defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.dock orientation && killall Dock')
|
|
if (deleteEnvError) {
|
|
console.error('An error occured while cleaning the dock orientation environment')
|
|
logRollbackInfo()
|
|
throw new Error(deleteEnvError)
|
|
}
|
|
|
|
return { filepath: `${outputPath}/bottom` }
|
|
}
|
|
}
|
|
|
|
function logRollbackInfo() {
|
|
console.info('Please manually run this command to make sure everything is properly reset:')
|
|
console.info('defaults delete com.apple.screencapture show-thumbnail && defaults delete com.apple.dock orientation && killall Dock')
|
|
}
|