slyfox Posted April 11, 2016 Share Posted April 11, 2016 (edited) Please excuse my lack of knowledge about java as I am just a regular user. I use TextExpander and found a JavaScript that can help me edit my reports. This is what I use in TextExpander // Start with the clipboard content var result = TextExpander.pasteboardText; // Replace double .. result = result.replace(/\".."/g,". "); // Replace duplicate words result = result.replace(/\b(\w+)\s+\1\b /g, "$1 ");; // Replace double spaces result = result.replace(/ /g, " "); Is there any way to make Alfred to the same? I know I can create a javascript workflow that can be triggers using a keyboard shortcut but how do I make it work with clipboard content? Edited April 11, 2016 by slyfox Link to comment
deanishe Posted April 11, 2016 Share Posted April 11, 2016 Getting clipboard contents: var app = Application('System Events'); app.includeStandardAdditions = true; var result = app.theClipboard(); Link to comment
slyfox Posted April 11, 2016 Author Share Posted April 11, 2016 Do I sue keyword to script? Do I use regular bin/bash language or choose JS in Alfred? var app = Application('System Events'); app.includeStandardAdditions = true; var result = app.theClipboard(); // Replace double .. result = result.replace(/\".."/g,". "); // Replace duplicate words result = result.replace(/\b(\w+)\s+\1\b /g, "$1 ");; // Replace double spaces result = result.replace(/ /g, " "); Link to comment
deanishe Posted April 11, 2016 Share Posted April 11, 2016 Do I use regular bin/bash language or choose JS in Alfred? /usr/bin/osascript (JS) Do I sue keyword to script? Probably, yeah. Or a Hotkey? Link to comment
slyfox Posted April 12, 2016 Author Share Posted April 12, 2016 Set a Hotkey with /usr/bin/osascript (JS) and nothing happens when I copy specific text to clipboard in text editor. var app = Application('System Events'); app.includeStandardAdditions = true; var result = app.theClipboard(); // Replace double .. result = result.replace(/\".."/g,". "); // Replace duplicate words result = result.replace(/\b(\w+)\s+\1\b /g, "$1 ");; // Replace double spaces result = result.replace(/ /g, " "); Link to comment
deanishe Posted April 12, 2016 Share Posted April 12, 2016 What kind of output have you connected it to? Link to comment
slyfox Posted April 13, 2016 Author Share Posted April 13, 2016 Hotkey -->> Run JS script That is all I have. Link to comment
deanishe Posted April 13, 2016 Share Posted April 13, 2016 And that's why it doesn't do anything. Add an output. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now