Skip to content

Instantly share code, notes, and snippets.

@Londeren
Last active February 21, 2024 02:44
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Londeren/9ca190bf4197206063096531d76d469a to your computer and use it in GitHub Desktop.
Save Londeren/9ca190bf4197206063096531d76d469a to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
// Raycast Script Command Template
//
// Dependency: This script requires Nodejs.
// Install Node: https://nodejs.org/en/download/
//
// Duplicate this file and remove ".template" from the filename to get started.
// See full documentation here: https://github.com/raycast/script-commands
//
// Required parameters:
// @raycast.schemaVersion 1
// @raycast.title Switch text case Upper/lower
// @raycast.mode silent
// @raycast.packageName Change Case
//
// Optional parameters:
// @raycast.icon 🔡
// Documentation:
// @raycast.description Change clipboard text to lowercase
// @raycast.author Sergey Lebedev @londeren
// @raycast.authorURL t.me/londeren
const { exec, execSync } = require('child_process');
const selectedText = execSync(`osascript -e 'tell application "System Events" to keystroke "c" using {command down}' -e 'delay 0.1' -e 'set theselectedText to the clipboard'`).toString();
if (selectedText) {
let changedText;
if (selectedText === selectedText.toLowerCase()) {
changedText = selectedText.toUpperCase().trim();
} else {
changedText = selectedText.toLowerCase().trim();
}
execSync(`osascript -e 'set the clipboard to "${changedText}"' -e 'tell application "System Events" to keystroke "v" using {command down}'`);
}
// console.log() displays output in fullOutput mode.
// console.log(`The arguments are: \n ${process.argv.join('\n ')}\n`)
// console.log(`osascript -e 'set the clipboard to "${changedText}"' -e 'tell application "System Events" to keystroke "v" using {command down}' -e 'delay 0.1'`)
// console.log(`Your query is "${query}"`)
// console.log(`Your query uri encoded is "${encodeURIComponent(query)}"`)
// console.log(`The uri is "${uri}"`)
// Uncomment the exec line below to open this query in your web browser.
// Use double quotes around the uri to avoid processing issues.
// exec(`open "${uri}"`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment