Jump to content

Saves the selected text to a file


Recommended Posts

Saves the selected text to a file. The new text adds to the old one.

Download

You find an interesting quote that you would like to keep. Usually you copy the text, run the reader and paste the text. And with Alfred you can select the text and press the hockey. All.

How it's done:

1. Create a Hotkey trigger.
2. As an option, select Selection in macOS.
3. Create Outputs → Write text File.
4. Connect them.
5. Prescribe the path to the text file, in which you will save everything.
6. Choose Append on the right, so that the new text does not erase the old one, but was added.
7. In the main field, insert the following:
{datetime: medium}
{clipboard}

Automaton, when you have selected the text and clicked hotkey, the text file will be added with the selected text, but the current date and time will appear before it.

You can create a diary and write to it. And you do not care which application you're writing in, even in the address bar.

 

## – for markdown.

 

Screen Shot 2017-11-13 at 20.32.26.png

Screen Shot 2017-11-13 at 20.32.54.png

Edited by Anton Maslak
Link to comment
  • 2 years later...
11 hours ago, vamose said:

Is there anyway to have the formatting and images copied, instead of just unformatted text?

 

And what would you be pasting in? This is possible, but is a bit more complicated. As images and formatted text would work with a regular text file. They require a more advanced editor, work, Evernote, etc.

 

If you could tell me that, I could probably get it working.

Link to comment

If I copy the content of a webpage, which is a mix of images & text, paste it in TextEdit, the format & images remain, the file is saved in Rich Text Format.

 

Maintaining text format is not critical, text must be copied though. But the images must be copied too.

 

If you look at the top of the page, author of the workflow has provided instruction & screenshot. I want to copy the text & image to a text document. 

 

Option 1: I highlight the required content, text & image. Copy the required content cmd + c, open a new TextEdit file & paste it using cmd + v. The whole text & image is copied. Which is what I currently do.

 

Option 2: Where I request your help is:

Highlight the section of interest, text  & image both, hit the assigned key stroke & the content gets appended to an assigned TextEdit file or a new TextEdit file.

 

Hope the above explains my requirement.

Edited by vamose
Link to comment
6 hours ago, vamose said:

If I copy the content of a webpage, which is a mix of images & text, paste it in TextEdit, the format & images remain, the file is saved in Rich Text Format

 

Rich text is not plaintext. You can't save text formatting and images to a text file. You would need to alter the workflow to save rich text files instead.

Link to comment

The workflow link below will paste the selection in Rich Text Format, but the problem is first you must select the content, then cmd + c to copy followed by the shortcut key stroke to paste in TextEdit file.

 

 

I request to have a workflow where you highlight the content & append to an existing TextEdit document with a single keystroke.

 

Inshort I need the best of both the workflow combined.

Edited by vamose
Link to comment
6 hours ago, vamose said:

I request to have a workflow where you highlight the content & append to an existing TextEdit document with a single keystroke.

 

If you want someone to make you a workflow, posting in another workflow's thread isn't the best place. I don't know what @Anton Maslak thinks of your idea, but you're asking for a workflow that works with a completely different file format.

 

You should try asking in the Workflow Help & Questions forum. Remember that it's generally much easier to get help building a workflow than to get somebody else to do all the work for you.

Link to comment

Deanishe & Vitor, Thanks for your feedback. I am fairly new and did try messing around with both the workflows to get what I wanted, but as no prior knowledge in development. I resorted to forum help with the design/ modification of the workflow.

 

Please suggest, how should I move forward?

Edited by vamose
Link to comment
7 hours ago, vamose said:

Guess my requirement is not trivial

 

No, I'm afraid it isn't. RTF is text in the same way that HTML or XML are text. You can't just blindly add more text to the end like you can with plaintext because the document would no longer be valid. That's why you can't easily modify this workflow to do it.

 

Here's an AppleScript that will open the specified document and simulate the keystrokes necessary to paste the clipboard at the end of it, then save and close the document. This isn't a very reliable way of doing it, but what you're asking is difficult and this is the only way I know to do it. The rest is up to you.

-- Path to document to append text to
property docPath : POSIX file "/Users/<username>/Desktop/Test.rtf"

-- return document whose path is thePath
on getDoc(thePath)
	tell application "TextEdit"
		repeat 50 times
			repeat with aDoc in documents
				if ((path of aDoc) as POSIX file) is equal to thePath then
					tell aDoc to activate
					return aDoc
				end if
			end repeat
			delay 0.1
		end repeat
	end tell
	return null
end getDoc

tell application "TextEdit"
	open docPath
	set theDoc to my getDoc(docPath)
	if theDoc is not null then
		tell application "System Events"
			key code 125 using command down -- ⌘↓ to go to end of file
			key code 36 -- ↩ to add a line break
			keystroke "v" using command down -- ⌘V to paste clipboard
			keystroke "s" using command down -- ⌘S to save document
			keystroke "w" using command down -- ⌘W to close document
		end tell
	end if
end tell

 

Link to comment

Thanks  a lot Deanishe for your help and an apple script. This is exactly what I wanted. It works fine so far. The only condition is the text document must be kept close recurring copy paste action.

 

I will continue to use what you have provided, will report in case of any concerns.

Edited by vamose
Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...