Yah, I can see how it might look like an XY problem, but here is more context/examples to maybe make sense of it.
I guess the bottom line is that I want to output some text, probably from a file, without losing the current clipboard contents. There are probably ways to do this that don't involve the clipboard at all. I'm just new to Mac in general, so I am probably unaware of them. On Windows I used AutoHotKey which was amaze-balls!
I'm trying to figure out some AppleScript and see if that will solve this. So far I have the following...
set SavedClipVar to (the clipboard as text)
set the clipboard to "Some sample text"
tell application "System Events" to keystroke "v" using {command down}
set the clipboard to SavedClipVar
I don't yet know how to bring in the contents of a text file, which is actually what I'll be doing on line #2. I'm just using sample text to see if the logic works.
When I bind that to a hotkey, I just get a -ding- sound as if I pressed an invalid key or something.
What am I missing? Any AppleScript wizards out there?
I also tried using shell commands:
do shell script "pbpaste > ~/temp-clipboard-file.txt"
do shell script "cat ~/texts/commonly-used.txt | pbcopy"
tell application "System Events" to keystroke "v" using {command down}
do shell script "cat ~/temp-clipboard-file.txt | pbcopy"
That doesn't work either. Gives the same -DING- sound as if I hit an invalid key.
I'll keep playing. If I figure it out, I'll share the solution. Any help appreciated.