Finding the name of the currently open window with Applescript

I know there are some pretty cool ways to do something as mundane as find the name of the currently selected window in Applescript, however in some apps AS just won’t function properly. I am using GoLive CS, the best version of that app, and unfortunately it seems to totally refuse to respond to Applescript, even giving “Adobe GoLive CS got an error: Can’t continue Activate.” when you use an Activate command on it. I really dislike DreamWeaver for its 1995 era interface, but I thought, if it’s more scriptable maybe I’ll give it a try, but lo, it has the same problem, so it’s back to trying to get GoLive CS to work.

Essentially, the app refuses to recognize any of the ways of reporting the currently open window. This script

set win_name to “”
tell application “System Events”
set app_name to name of the first process whose frontmost is true
end tell
tell application app_name
set win_count to count of windows
if (win_count is greater than 0) then
set win_name to name of window 1
end if
end tell
say win_name

should say the name of the currently open window, and it works in just about every app when I set it up as a Quickeys script. However I get “Could not play script due to error: Adobe GoLive CS got an error: every Window doesn’t understand the count message” with GoLive CS open :frowning:

So can anyone tell me a way of directly hacking this to work? A list of open windows that System Events is watching that I can ping? Some other way to get System Events to report the name of the front window?

Hi,

Golive CS has an own Activate command, so activating the program works only with this syntax

activate application "Adobe GoLive CS"

You’re right, GoLive CS is scriptable, but very poor. To get the name of the front window, try this


activate application "Adobe GoLive CS"
tell application "System Events"
	tell process "Adobe GoLive" -- the name of the process is without CS!!
		repeat with i in (get name of windows)
			if contents of i is not missing value then
				set frontWindow to contents of i
				exit repeat
			end if
		end repeat
	end tell
end tell

Wah! You are da man, thank you for coming up with this. It works great. I spent all weekend trying to get this working :slight_smile:

Hrrm, one more small question if I may. There doesn’t seem to be a way to access “Replace All” other than by clicking on the button in the find/replace palette. Any idea how to find what that button is called and/or how to click on it with System Events?

in the dictionary of Adobe GoLive CS there are find and replace commands, but I haven’t tested it.
If it doesn’t work, it could be possible with GUI scripting.

I’m sorry, I don’t use GoLive CS (it’s accidentally still on my PowerBook, I left it beside the CS3 Suite)
and it’s the german version, so I can’t barely help you with the script

Hi, the dictionary reports this for that command:

Replace‚v : Replace a string of text with different text
Replace [text] : The text to find; if omitted, the current slection is used
[Using text] : The text to be used for the replacement
[Applying list of Wraparound/From top/Backwards/Ignore case/Words] : Options to be applied to the replacement
→ boolean : Returns a Boolean to indicate whether the text was found

I tried this script as a test:

activate application “Adobe GoLive CS”
tell application “Adobe GoLive CS”
Replace “products” Using “items” Applying “Ignore Case”
end tell

but get:

Adobe GoLive CS got an error: “products” doesn’t understand the Replace message.

so it seems that GoLive CS is scriptable, but there’s some “voodoo” to make the commands work? Is there a different approach I need to be taking?

Also, I see there is some code for, say, selecting the entire paragraph the cursor is in, but all my attempts are bringing up the same “did not understand” error. Any thoughts on how this might work? I am trying to basically remove some existing paragraphs and paste in new ones.

The dictionary code for that command is here:

Select paragraph‚v : Selects all lines backwards and forwards from the current line up to an empty line
Select paragraph
[Between specifier] : The range of lines or characters to limit the search to

Hmm, still plugging away but not doing to well. I can’t make GoLive react to any of my scripts. Incidentally if anyone is able to help me with this as a consultant I’d be open to the idea. Let me know, thanks.

Just seeing if anyone can help me with this. I am currently trying to get any kind of search/replace to work, but scripting GoLive is like pulling fingernails. I am about to give up, but it impossible to click the “replace all” button with system events? into on that button, according to Accessibility Inspector, is as follows:

<AXApplication: “GoLive”>
<AXWindow: “Find Content”>

Attributes:
AXRole: “AXWindow”
AXRoleDescription: “dialog”
AXSubrole: “AXDialog”
AXChildren: “<array of size 6>”
AXParent: “<AXApplication: “GoLive”>”
AXTitle: “Find Content”
AXSize (W): “w=378 h=382”
AXPosition (W): “x=1365 y=504”
AXMain (W): “true”
AXMinimized (W): “false”
AXCloseButton: “”
AXZoomButton: “”
AXMinimizeButton: “”
AXTitleUIElement: “<AXStaticText: “Find Content”>”
AXGrowArea: “”

Actions:
AXRaise - raise

Alternately, I am trying to do the search/replace in TextWrangler, which should be up to the task. I am getting some weird voodoo though. This script works if I have an already open window with text in it:

tell application “TextWrangler”
activate
replace “href="/” using “href="http://affiliates.jlist.com/click/1872?url=http://www.jlist.com/” searching in text 1 of text document 1 options {search mode:literal, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
end tell

But this script, below? Nope, it won’t replace the stuff properly. Why does the creation of a new window cause the script to not report any results? It’s totally baffling.

set sample_text to the clipboard

set sample_text to the clipboard
tell application “TextWrangler”
activate
make document with properties {text:sample_text}
replace “href="/” using “href="http://affiliates.jlist.com/click/1872?url=http://www.jlist.com/” searching in text 1 of text document 1 options {search mode:literal, starting at top:false, wrap around:false, backwards:false, case sensitive:false, match words:false, extend selection:false}
end tell