martin wrote:Here's an AppleScript that does such a thing without using the clipboard
Marvelous! This is pure poetry! Especially this "JavaScript" thing that suddenly pops up out of nowhere and brings the tension and suspense to a climax. I'm sure Shakespeare would go green with envy if he were still alive.
I modified the second script slightly so that it can now copy text from any application, not only from Safari. It works fine with PDFs.
Code: Select all
tell application "System Events"
key down {command}
keystroke "c"
key up {command}
end tell
delay 0.25
tell application "Nisus Writer Pro"
activate
tell application "System Events"
key down {command}
keystroke "v"
key up {command}
keystroke return
keystroke "----"
keystroke return
end tell
end tell
tell application "Safari" # or change to match the correct application
activate
end tell
Question:
Instead of writing:
tell application "Safari"
in the last part, how could we track the name of the application we started from? Once we have that command, it should be used instead. Thus the script would not be limited to Safari anymore. Unfortunately I don't know (yet) how to accomplish this. Can someone please help?
Now the question arises how to use these scripts. I place mine into the systemwide Scripts folder. It's located here:
/Users/ME/Library/Scripts
Next I used a shortcuts manager to assign shortcuts to the scripts. Every time I now select text in an application other than Nisus and press the key combination, the corresponding script is triggered. This is much better and FASTER than right-clicking for the Services menu.
Any shortcuts manager will do. I use
Apptivate because it's a menubar application and is very easy to use. One could also use
Spark which is a powerful and easy to use free shortcuts manager,
Keyboard Maestro, or something else. Unfortunately OS X doesn't seem to have a shortcuts manager yet that can launch a script, an application or a file with a keystroke. Or am I missing something?
I think these scripts can be of great value, not only to the original poster, but to all Nisus users who are doing research and need to collect material from the web.
Three things still need improvement:
1) When I'm in Nisus and I (accidentally) execute the assigned keystrokes, the scripts will start running,… with unpredictable results. I need a command that prevents the scrips from running when the user starts in Nisus:
tell application "System Events"
How can I call "System Events" at the beginning and *exclude* Nisus Writer Pro?
2) It would be great to let the scripts grab the URL when in a web browser and enter it at the end of the pasted snippet, preferably in curly brackets, so that it could be easily identified later with a macro and removed, if necessary.
3) If the selected text is from a PDF, then it would be good to grab the name of the PDF and include it at the end of the pasted snippet, just like in 2) above.
Edit:
The assigned key combination does not behave as expected, i.e. it seems I must hold down modifier key(s) while typing the chosen keyboard character TWICE. Although I assigned the script the shortcut Command+ü (on the German keyboard), I must hold down the command key and type "ü" *twice*. I have tried all sorts of key combinations, and it's always the same. Has anyone an explanation for this?