Override Script Editor default window sizes

A nice side-effect of the new app-specific shortcuts feature in my FastScripts utility is that you can easily override the standard keyboard shortcuts in an application if you feel they should do something “in a better way.”

Something that’s always annoyed me about Script Editor is that the default “new document” and “dictionary” windows are positioned in awkward locations on the screen.

So I wrote two simple scripts that ask Script Editor to do the intended action and then adjust the size of the new window accordingly. If I set these up as “App-Specific” scripts in FastScripts, then cmd-N and cmd-Shift-O, respectively, now make new document and open dictionary followed by a resize to a more appropriate (for me) screen positioning.


-- Create a new document and immediately change its screen position
tell application "Script Editor"
	set newDoc to make new document at end of documents
	set bounds of window of newDoc to {1, 22, 610, 956}
end tell


-- Open a dictionary and immediately change its screen position
tell application "Script Editor"
	open (choose application with «class dict» and multiple selections allowed)
	set bounds of window 1 to {612, 22, 1280, 956}
end tell

You’ll see if you try out the above scripts that the new “Editor” document opens up right next to the new “dictionary” window. I’ve expanded on this idea to create a “New Script for Current App” script that I assigned a global shortcut to. It opens the dictionary for the active application, and creates a new empty document with a “tell application [Blah]” block prepopulated in the text:


set myAppName to NameOfFrontmostApp()
OpenAppDictionary()
CreateNewScriptEditorDocument(myAppName)
tell application "Script Editor" to activate

on CreateNewScriptEditorDocument(targetAppName)
	tell application "Script Editor"
		set myDoc to make new document at end of documents
		set bounds of window of myDoc to {1, 22, 610, 956}
		set text of myDoc to "tell application "" & targetAppName & ""

end tell"
	end tell
end CreateNewScriptEditorDocument

on OpenAppDictionary()
	tell application "System Events"
		set frontApp to first application process whose frontmost is true
	end tell
	
	tell application "Script Editor"
		open (file of frontApp) as alias
		set bounds of window 1 to {612, 22, 1280, 956}
	end tell
end OpenAppDictionary

on NameOfFrontmostApp()
	tell application "System Events"
		set frontApp to first application process whose frontmost is true
	end tell
	return name of frontApp
end NameOfFrontmostApp

Now if I’m in Safari, for instance, and I want to write a new safari script, I just hit “cmd-shift-option-N”, and Script Editor activates with a new safari script template and the safari dictionary right next door.

Thanks for the tip.