0

In BBEdit and AppleScript I can loop through a string and set the string to the clipboard with:

set the clipboard to jsonString

I can then make a new text document and save it with:

set jsonParseFile to (name of project window 1) as text
save text document jsonParseFile to file ("some:location") without saving as stationery
set jsonParseFile to (name of active document of project window 1) as string

but when I try to paste the contents of the string with paste I get an error indicating that paste is not understood:

BBEdit got an error: active document doesn’t understand the “paste” message.

So when I remove:

set jsonParseFile to (name of active document of project window 1) as string

and use:

paste of active document

I get the same error but when I just use paste I'm returned the error of:

BBEdit got an error: Can't continue paste.

How can I paste the string into the file variable jsonParseFile which is the front most file without calling on:

tell active document of project window 1 to paste

but rather with something like:

tell active document of file jsonParseFile to paste

that passes jsonParseFile? When I search I haven't found anything beyond keystroke and I'm not wanting to use and when I check the dictionary for answers I'm not getting much:

enter image description here

DᴀʀᴛʜVᴀᴅᴇʀ
  • 7,681
  • 17
  • 73
  • 127

1 Answers1

2

This is a simple example how to paste a string into the active document

set the clipboard to "Hello World"

tell application "BBEdit"
    tell active document of project window 1
        paste
    end tell
end tell
vadian
  • 274,689
  • 30
  • 353
  • 361
  • I get that but I'm trying to tell the variable `jsonString` not just the project window. Anything could accidentally be set as the active project window. – DᴀʀᴛʜVᴀᴅᴇʀ Nov 30 '17 at 17:16
  • @Gʀɪᴍ, your said "Anything could accidentally be set as the active project window." while that may be true, nonetheless the onus in upon the programmer to ensure the proper target has focus to be acted upon before any action is taken. – user3439894 Nov 30 '17 at 17:49
  • @user3439894 but that isn't the intent of the question. I wanted to be granular in my targeting to ensure any possible issues were to arise and that answer doesn't reflect that. If there are multiple windows open then that could be an issue. – DᴀʀᴛʜVᴀᴅᴇʀ Nov 30 '17 at 17:51