OK, I admit I’m new to all this but hopefully quick to learn.
Could some one help me convert Rob’s script: “safari selection to script” to “safari selection to BBEdit” without all the commented info at the beginning of the document it creates in BBEdit?
In other words just the selected text would appear in BBEdit and nothing else. Changing the script to run in BBEdit isn’t the issue, it’s getting rid of all the heading info.
tell application "Safari" to ¬
set selection_ to (do JavaScript "getSelection()" in document 1) as string
if selection_ is not "" then
tell application "BBEdit 6.5" to ¬
make new text window with properties {text:selection_}
else
display dialog "Nothing selected in Safari's front window."
end if
I may be doing something wrong but when I run your code with a selection in Safari nothing happens. If I run it without a selection in Safari, it does produce the dialog which says nothing is selected. Script Editor returns the result:
I just tested the code again and it works as expected. Do you have JavaScript enabled in Safari? Do any of the other Safari selection scripts work for you? Did you try Greg’s script?
As far as I know, the only way to do that is with UI scripting. UI scripting is included in Panther and requires the (no longer available) beta version of System Events in Jaguar.
tell application "Safari" to activate
tell application "System Events" to keystroke "c" with {command down}
set cb to the clipboard
Yes, as long as the source window is the front window in Safari, it doesn’t matter if Safari is frontmost. I’m surprised this doesn’t compile in 10.2 with the GUI scripting beta.