Cannot set bounds

Hello Everyone,

I am trying to automatically open the last saved file and set its bounds but fail to do so directly from the finder command. Instead I found a work around by doing it through excel.

But I would like to make my code line not having to go through excel!

Could anyone explain me where I am wrong?

Here is the code


tell application "Finder"
	
	open (last item of (sort (get files of folder "Groups:sales:RLPI_Proforma Invoice:RLPI Format:") by modification date))
	set the bounds of the last open window to {0, 55, 728, 826} -- Using this command nothing happens and this is where I would like the command to work as I might open any kind of documents.
end tell

--This is my workaround...
tell application "Microsoft Excel" to set the bounds of the front window to {0, 55, 728, 826} -- This command of course works but this is the line I would like to cancel.

Thanks,

Hi Claude,

When Finder opens the file, what application does it open with? You cannot set the bounds of a non-Finder window through Finder. i.e. it is not a Finder window.

gl,
kel

Hi Claude,

It has been a while since I’ve done this, but you can try this example:

set f to choose file

tell application "Finder"
	set creator_type to creator type of f
end tell
if creator_type is missing value then
	tell application "System Events"
		set the_path to path of (default application of f)
	end tell
	set the_app to application the_path
else
	tell application "Finder"
		set the_id to (id of application file id creator_type)
	end tell
	set the_app to application id the_id
end if
tell the_app
	activate
	open f
	set bounds of front window to {0, 55, 728, 826}
end tell

In this script, you choose the file, but you can modify it later. Either the file opens with the default application or it opens with the application that created it.

Maybe there’s an easier way. But all the gurus seem to be sleeping.

Edited: one more thing. if the application that opens it is not scriptable, then you may not be able to set the bounds of the window.

gl,
kel

Hi,

last open window is invalid syntax

if the file is an Excel file anyway, it’s not a workaround but the best choice to open the file in Excel and set the bounds


tell application "Finder"
	set theItem to (last item of (sort (get files of folder "Groups:sales:RLPI_Proforma Invoice:RLPI Format:") by modification date)) as alias
end tell
tell application "Microsoft Excel"
	open theItem
	set the bounds of the front window to {0, 55, 728, 826}
end tell


creator type is outdated for a long time

Hi Stefan,

I read that, but still notice that there are apps that use it creator type. For testing, I’ve been using TextEdit and Tex-Edit Plus with rtf files. Wasn’t sure what application op wanted to open the file with.

Thanks for pointing that out.

Have a good day,
kel

Hello Kel & Stefan,

Thank you both for answering my question.

I will then stick to what I called my “workaround”…

Thanks

Hi Claude,

No problem. It was an interesting exercise anyway. I modified the script a little if anyone is interested:

set f to choose file

tell application "System Events"
	set creator_type to creator type of f
end tell
if creator_type is missing value then
	tell application "System Events"
		set the_path to path of (default application of f)
	end tell
	set the_app to application the_path
else
	tell application "Finder"
		set the_id to (id of application file id creator_type)
	end tell
	set the_app to application id the_id
end if
tell the_app
	launch
	activate
	open f
	set bounds of front window to {0, 55, 728, 826}
end tell

gl,
kel