Add textedit RichText command (#120)

This commit is contained in:
Valentin Perignon 2020-12-22 18:55:28 +01:00 committed by Yann Bertrand
parent 62f1f52c00
commit 13c9d2de80
No known key found for this signature in database
GPG key ID: F87B5B748AB00DAE
6 changed files with 205 additions and 0 deletions

View file

@ -589,6 +589,35 @@ categories:
- value: "~/Pictures/Simulator Screenshots"
versions: [Catalina]
- folder: textedit
name: TextEdit
description:
TextEdit permet d'ouvrir et de modifier des documents de texte enrichi (rich text), texte brut (plain text) et HTML.
keys:
- key: RichText
domain: com.apple.TextEdit
title: Définir le format de document par défaut
description:
Définir le format de document par défaut comme texte enrichi (.rtf) ou texte brut (.txt).
param:
type: bool
examples:
- value: true
default: true
text: Texte enrichi activé.
image:
filename: "true.png"
width: 740
height: 451
- value: false
text: Texte enrichi désactivé.
image:
filename: "false.png"
width: 740
height: 451
versions: [Big Sur]
after: killall TextEdit
- folder: timemachine
name: Time Machine
description:

View file

@ -594,6 +594,34 @@ categories:
- value: "~/Pictures/Simulator Screenshots"
versions: [Catalina]
- folder: textedit
name: TextEdit
description:
TextEdit allows you to open and edit rich text, plain text and HTML documents.
keys:
- key: RichText
domain: com.apple.TextEdit
title: Set default document format
description:
Set default document format as rich text (.rtf) or plain text (.txt).
param:
type: bool
examples:
- value: true
default: true
text: Rich text is enabled.
image:
filename: "true.png"
width: 740
height: 451
- value: false
text: Rich text is disabled.
image:
filename: "false.png"
width: 740
height: 451
versions: [Big Sur]
after: killall TextEdit
- folder: timemachine
name: Time Machine

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.4 KiB

View file

@ -0,0 +1,74 @@
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 true', '1',
''
)
.openApp('TextEdit', fileName)
.moveAndResizeApp('TextEdit', 0, 0, 744, 451)
.captureApp('TextEdit', `${outputPath}/false.png`)
.deleteDefault(
'com.apple.TextEdit',
'RichText',
'killall -SIGKILL 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)
}
}

View file

@ -0,0 +1,74 @@
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.rtf';
await manageFile(filename, true)
await addContentToFile(filename, "{\\rtf1\\ansi\\ansicpg1252\\cocoartf2577\\cocoatextscaling0\\cocoaplatform0{\\fonttbl}{\\colortbl;\\red255\\green255\\blue255;}{\\*\\expandedcolortbl;;}\\paperw11900\\paperh16840\\margl1440\\margr1440\\vieww11520\\viewh8400\\viewkind0}")
const runner = new MacRunner()
await runner
.setDefault(
'com.apple.TextEdit',
'RichText',
'-bool true', '1',
''
)
.openApp('TextEdit', filename)
.moveAndResizeApp('TextEdit', 0, 0, 744, 451)
.captureApp('TextEdit', `${outputPath}/true.png`)
.deleteDefault(
'com.apple.TextEdit',
'RichText',
'killall -SIGKILL TextEdit'
)
.run()
await manageFile(filename, false);
} catch (runnerError) {
throw new Error(runnerError)
}
try {
await compressPngImage(`${outputPath}/true.png`, outputPath, 'true')
} catch (compressPngImageError) {
throw new Error(compressPngImageError)
}
return { filepath: `${outputPath}/true` }
}
}
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)
}
}