Side by side view of script in Script Editor

Hello all,

I wanted an easy way to view a script next to itself so that I could revise it with an easy reference. My script works as an application or in the script menu, acting on the frontmost script window.

What I have been unable to do is make it a droplet that will open the script in Script Editor. It either opened its own script or returned various errors depending on my approach. I’ll probably feel silly when somebody shows how simple the solution is.

EDIT: The section for saving works well in the editor, but doesn’t outside of it. Without saving, it the script works fine.


--on open
set windowOne to {0, 22, 600, 922}
set {b1, b2, b3, b4} to windowOne
set windowTwo to {(b1 + 2 + (b3 - b1)), b2, (b3 + (b3 - b1)), b4}

tell application "Script Editor"
	
	make new document
	
	set the bounds of window 1 to windowOne
	set the bounds of window 2 to windowTwo
	
	set theScript to (get contents of second document)
	copy theScript to (contents of first document)
	compile first document --Second document became first after previous action.
	
	set theName to (get name of second document)
	set newDocName to (theName & "(copy)") --unlikely to overwrite anything
	save first document
	
	tell application "System Events" to keystroke newDocName
	delay 1 --or the "Save" button clicks too soon - couldn't find a better way to do this
	tell application "System Events" to tell window 1 of process "Script Editor"
		tell button "Save" of sheet 1
			click
		end tell
	end tell
	
	
	
	
end tell
--end open

I also worked on a full screen version, but it only works Script Editor. Otherwise it returns “can’t get bounds of window 1”. I’m hoping somebody else will see what I’m missing.


--on open
tell application "Script Editor" to copy (run script "tell application \"Finder\" to desktop's window's bounds") to bounds of window 1 --found this at http://bbs.applescript.net/viewtopic.php?id=14236

set {b1, b2, b3, b4} to (get bounds of window 1)
set windowOne to {b1, b2, ((b3 / 2) - 1), b4}
set windowTwo to {(b3 / 2) + 1, b2, b3, b4}

tell application "Script Editor"
	
	make new document
	
	set the bounds of window 1 to windowOne
	set the bounds of window 2 to windowTwo
	
	set theScript to (get contents of second document)
	copy theScript to (contents of first document)
	compile first document --Second document became first after previous action.
	
	set theName to (get name of second document)
	set newDocName to (theName & "(copy)") --unlikely to overwrite anything
	save first document
	
	tell application "System Events" to keystroke newDocName
	delay 1 --or the "Save" button clicks too soon - couldn't find a better way to do this
	tell application "System Events" to tell window 1 of process "Script Editor"
		tell button "Save" of sheet 1
			click
		end tell
	end tell
	
end tell
--end open

Thanks in advance,

j

I solved one of my problems on my own.

The first line needed to be

tell application "Finder" to desktop's window's bounds

so now I have this

tell application "Finder" to desktop's window's bounds --found this at http://bbs.applescript.net/viewtopic.php?id=14236
set {b1, b2, b3, b4} to result
set windowOne to {b1, b2, ((b3 / 2) - 1), b4}
set windowTwo to {(b3 / 2) + 1, b2, b3, b4}
tell application "Script Editor"
	
	make new document
	
	set the bounds of window 1 to windowOne
	set the bounds of window 2 to windowTwo
	
	set theScript to (get contents of second document)
	copy theScript to (contents of first document)
	compile first document --Second document became first after previous action.
	
	
	
end tell

I’m still working on making it a droplet (that actually works) and sorting out why this only works in the Script Editor

set theName to (get name of second document)
	set newDocName to (theName & "(copy)") --unlikely to overwrite anything
	save first document
	
	tell application "System Events" to keystroke newDocName
	
	delay 2 --or the "Save button clicks too soon-couldn't find a better way to do this
	tell application "System Events" to tell window 1 of process "Script Editor"
		tell button "Save" of sheet 1
			click
		end tell
	end tell
	

Thanks for any help

j

Okay, I realized why the script didn’t work as a droplet and am appropriately embarrassed.

My mistake isn’t shown in the original post because I cut out the mess that my attempts had become as I compounded error with error.

This is my droplet script:

on open theScript
	
	tell application "Finder" to desktop's window's bounds --found this at http://bbs.applescript.net/viewtopic.php?id=14236
	set {b1, b2, b3, b4} to result
	set windowOne to {b1, b2, ((b3 / 2) - 1), b4}
	set windowTwo to {(b3 / 2) + 1, b2, b3, b4}
	
	tell application "Script Editor"
		activate
		open theScript
		
		make new document
		
		set the bounds of window 1 to windowOne
		set the bounds of window 2 to windowTwo
		
		set theScript to (get contents of second document)
		copy theScript to (contents of first document)
		compile first document --Second document became first after previous action.
		
		
	end tell
end open

I am still trying to figure out the saving bit.

j

And now the saving works.

It still needs some refinement, which I’ll post later for anybody who might be interested, but I managed to get it up and running.

j


--the "on run"  and "on open" bits can be removed to run this from the menu
on run
	beep
	display dialog return & "Drop a script on the application's icon" with icon caution buttons {"Okay"} default button "Okay"
end run

on open theScript
	
	tell application "Finder" to desktop's window's bounds --found this at http://bbs.applescript.net/viewtopic.php?id=14236
	set {b1, b2, b3, b4} to result
	set windowOne to {b1, b2, ((b3 / 2) - 1), b4}
	set windowTwo to {(b3 / 2) + 1, b2, b3, b4}
	
	tell application "Script Editor"
		activate
		open theScript
		
		make new document
		
		set the bounds of window 1 to windowOne
		set the bounds of window 2 to windowTwo
		
		set theScript to (get contents of second document)
		copy theScript to (contents of first document)
		compile first document --Second document became first after previous action.
		
		set theName to (get name of second document)
		set newDocName to (theName & "(copy)") --unlikely to overwrite anything
		save first document
		
		tell application "System Events" to keystroke newDocName
		delay 1 --or the "Save button clicks too soon-couldn't find a better way to do this
		tell application "System Events" to tell window 1 of process "Script Editor"
			tell button "Save" of sheet 1
				click
			end tell
		end tell
		
	end tell
end open

--capitalj
--5/26/2006

I get an error:
"Can’t get bounds of window of
<> of application
“Finder”.

I just tried the versions in posts #3 and #4 and they worked fine.

A problem I sometimes have when compiling a script that includes

desktop's window's bounds

is that sometimes it compiles as

window of desktop's bounds

usually because of a typo, and it will generate that error. Make sure you copied or typed it correctly.

How about losing the GUI parts by just using duplicate.


--the "on run"  and "on open" bits can be removed to run this from the menu
--on run

on run
	beep
	display dialog return & "Drop a script on the application's icon" with icon caution buttons {"Okay"} default button "Okay"
end run
on open theScript
	tell application "Finder" to desktop's window's bounds --found this at http://bbs.applescript.net/viewtopic.php?id=14236
	tell application "Finder"
		set {b1, b2, b3, b4} to result
		set windowOne to {b1, b2, ((b3 / 2) - 1), b4}
		set windowTwo to {(b3 / 2) + 1, b2, b3, b4}
		set newScript to duplicate theScript
	end tell
	tell application "Script Editor"
		activate
		open theScript
		open newScript
		set the bounds of window 1 to windowOne
		set the bounds of window 2 to windowTwo
		compile first document
		compile second document
	end tell
end open

--capitalj
--5/26/20066

The thought never occurred to me. :rolleyes: