finding a specific window

Hi,

I’m trying to set focus on an opened window amongst others in BBEdit app, but I get a problem finding these windows :

tell application "Finder"
	set myVarArray to get the clipboard -- list of files (already opened in BBEdit) is copied directly in the folder - works
end tell

set Y to 1
repeat with Y from 1 to count of myVarArray
	tell application "BBEdit"
		(find_window whose name is (item Y of myVarArray))
--here an action for find and replace some placeholders - works
	end tell
end repeat

I’ve tried many ways to get focus on a specific window, but no success. All I get is :

error "Il est impossible d'obtenir find_window whose name = item 1 of 
\"myFile1.html
myFile2.html
myFile3.html
myFile4.html
myFile5.html\"." number -1728

Testing on “myFile1.html” , all I’ve found is :

tell application "BBEdit"
activate (window whose name is "myFile1.html")
end tell

or :

tell application "BBEdit"
set front window to window whose name is "myFile1.html"
end tell

or:

tell application "BBEdit"
	find_window whose name is ("myFile1.html")
end tell

Any idea ?

Thanks for your help

Phil

The error message indicates that myVarArray is not an AppleScript list. It looks more like something gotten with a do shell script command.
When that is the case you can get an A/S list like so:

set myVarArray to paragraphs of (do shell script "whatever")

If you must use the clipboard you can:

set myVarArray to paragraphs of (get the clipboard)

Hi alastor933

Thanks for your response.
My skills are not so strong for using “do shell script” :°)
The difference I can see with your script is in the format of resulting data:

with : “set myVarArray to paragraphs of (get the clipboard)” I get :
can’t get find_window whose name = item 1 of {“myFile1.html”, “myFile2.html”, “myFile3.html”, “myFile4.html”, “myFile5.html”, “myFile6.html”}.

…and with : “set myVarArray to get the clipboard” I get :
error "can’t get find_window whose name = item 1 of
“myFile2.html”
“myFile3.html”
“myFile4.html”
“myFile5.html”
"myFile6.html".
" number -1728

…but none of both can get the window of item 1…

regards

Phil

This should enable you to get the document you want in focus:

--Selecting documents in BBEdit
--BP 2011
(*
See "Referencing Documents" on Page 292 of BBEdit User Manual

Windows are pretty much irrelevant to getting your BBEdit document up front and active anymore.

To run this example, first create 2 or more BBEdit document windows and populate them with various
untitled text documents. Be sure there's an "untitled text 3" in the mix somewhere.

The example will sequentially display every document you created, regardless of window,
and then display a document found via its name, "untitled text 3".

*)
set targettexteditor to "BBEdit"
set finaltargetdoc to "untitled text 3"
set doclst to {}


tell application targettexteditor
	activate
	
	set doclst to name of every document
	set doccount to count of doclst
	
	repeat with n from 1 to doccount
		set targdoc to document n
		select targdoc
		delay 1
	end repeat
	
	set targdoc to first document whose name is finaltargetdoc
	select targdoc
	
end tell
return doclst

Hi Partron22

Thanks for your response.
Your script works fine! I took my time for exploring and understanding it, plus including 2 complex (for me) loops for having the final result I desired !

Many thanks

Phil