When TextEdit doc is opened from folder x set the bounds…

I love to run a script that does a bunch of cool things revolving around opening a new TextEdit doc & setting the bounds to {0, 22, 1280, 796} (covers the entire screen on my macbook). Unfortunately, when I launch the file from Finder of from Dock after it having been saved, it won’t retain the beautiful boundaries. What if a script could do:

in response to the opening of all files in folder x
check to see whether they are TextEdit
and if they are
make the bounds of the window they open in equal to {0, 22, 1280, 796}

and I know the script wouldn’t actually look anything like this.

I’m running Leopard, btw.

I think you need to check the path of the open doc. Also the simple way would be to have this script runs as a stay open app, using a on idle. But a better way would to use a Users Agent (luanchd,).

Here is the script, you would need to add the on idle bits if you wanted to go down that path.
And save it as a stay onep app.

But if you wanted to use it with a Users Agent, then save it as a text file, and chmod it to be executable.
And use a program like Lingon to create your Agent.

#!/usr/bin/osascript
property file_ext : "txt"

tell application "TextEdit"

	set docPath to path of document 1
	set docPathP to ((POSIX file docPath) as alias)
	set docName to name of document 1
	tell application "Finder" to set {FileType, NameExten} to {file type of docPathP, name extension of docPathP}
	
# check for path
if docPath contains "/Users/userName/Desktop/patheTo/textfiles/" then
		# check for extesion
if {FileType, NameExten} contains file_ext then
			set bounds of window docName to {0, 22, 1280, 796}
		end if
	end if
end tell

Here is an example of a Agent.
It will run at login and run the above script every 5 seconds.

You could link it to only run when TextEdit is running.
And if you are using spaces then you will need to work out how to Textedit change the bounds in of the window if its not in the current one. (That maybe a bug in my system?)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>Label</key>
	<string>TextBoundsTest</string>
	<key>ProgramArguments</key>
	<array>
		<string>/Users/user/Desktop/TESTS/testBounds.applescript</string>
	</array>
	<key>RunAtLoad</key>
	<true/>
	<key>StartInterval</key>
	<integer>5</integer>
</dict>
</plist>

Hi again :slight_smile:

I know, I know, I’m a newbie. but how exactly do I customize that script file to make it work?

And if I use the Agent I’d be using it to schedule runs of that script, right?

And how do you link it to only run when TextEdit is running, could you link it to only run when TextEdit is generating a new window, that’d be cool.

Thanks for that and thanks in advance.

Yes.

I have added a check in the script.

#!/usr/bin/osascript
property file_ext : "txt"
property youFolderPath : "/Users/USERNAME/Desktop/TextDocs/"
# check to see if Textedit is running.

tell application "System Events"
	if (exists application process "TextEdit") then
		#if it is then  go to the run_me() subroutine below
		my run_me()
	end if
end tell

on run_me()
	try
		tell application "TextEdit"
			
			set docPath to path of document 1
			set docPathP to ((POSIX file docPath) as alias)
			set docName to name of document 1
			tell application "Finder" to set {FileType, NameExten} to {file type of docPathP, name extension of docPathP}
			
			# check for path
			if docPath contains youFolderPath then
				# check for extesion
				if {FileType, NameExten} contains file_ext then
					set bounds of window docName to {0, 22, 1280, 796}
				end if
			end if
		end tell
	end try
end run_me

1, Replace “/Users/USERNAME/Desktop/TextDocs/” with the path of your text folder in.
2, Save the script as a TEXT file some where.
3,Open terminal. and Type the he command

4, drag and drop the file you saved on to the terminal window.
( This will write the path of the file for you, which is needed in the command)
example:

.
5, hit return/enter.
The file should now be executable.
6, Download Lingon
-IN Lingon.

1, Click the New Button.
2, choose my agnets, and then OK it.
3, In the Name field type the name for the agent.
4, click ‘CHOOSE’ in the what field, and Nav to you new file. Select It and and the click ‘Open’
5, Type 5 in the ‘Run it Every:’ and choose ‘seconds’, you want it to run.

Click Save.

Log out and back in.

Note I have note tested this on my system. But it should work.
You will need to do more research to tweak it.

Yes it would :slight_smile:

Hi Mark,

in Leopard there is a “shortcut”


if application "TextEdit" is running then
	#if it is then  go to the run_me() subroutine below
	run_me()
end if

Hi Stefan, Cheers, :slight_smile: