mirror of
https://github.com/yannbertrand/macos-defaults
synced 2024-12-13 13:12:30 +00:00
✨ Add textedit RichText command (#120)
This commit is contained in:
parent
62f1f52c00
commit
13c9d2de80
6 changed files with 205 additions and 0 deletions
|
@ -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:
|
||||
|
|
28
defaults.yml
28
defaults.yml
|
@ -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
|
||||
|
|
BIN
images/textedit/RichText/false.png
Normal file
BIN
images/textedit/RichText/false.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 3.1 KiB |
BIN
images/textedit/RichText/true.png
Normal file
BIN
images/textedit/RichText/true.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
74
record/textedit/RichText/false.js
Normal file
74
record/textedit/RichText/false.js
Normal 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)
|
||||
}
|
||||
}
|
74
record/textedit/RichText/true.js
Normal file
74
record/textedit/RichText/true.js
Normal 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)
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue