Is there a way to copy a text file (.txt) to the clipboard without having to open it and do a select all>file>copy? Any help would be appreciated
If you’re going to be scripting something, you probably don’t actually want to set the clipboard to a value when you can just use a variable. That said, if you actually do want the clipboard set to the contents of a text file, this should do it:
Jon
[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]
jonn8
I didn’t realize it was so easy. I’m amazed sometimes at what applescript can do. And thank you for the reply. My script cleans an email eg headers, advertising etc by using sed. And I needed a way to read the cleaned text (.txt) to the clipboard without opening text edit.
I do have a question regarding sed. I seem to recall that you (jonn8) know alot about shell scripting. Here’s the syntax I use to delete all text between ‘-’ and ‘-’: sed ‘/-/,/-/ d’. How do delete text from ‘----------’ to the end of the file. I’m having problems figuring out the ‘end of the file’ part.
Well, I actually haven’t spent much time with sed. I can give you some pointers with regular expressions but I’d have to look more closely at the sed man pages. Again, however, if you are looking for a method to just get text into your script, putting it onto the clipboard and going from there probably isn’t the best way to to go since you will obliterate what was on the clipboard (though you could save the contents of the clipboard and restore it at the end of the script, this seems like a lot of work) when you could just read the contents of the file to a variable, massage the text, and do something else with it.
As to the question about deleting from “---------” to the end, you can do this very easily in vanilla AppleScript and then write it to a new text file using a simple shell script:
Jon
[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]