Script to Launch App & Size Window

In my efforts to learn AppleScript, I’ve started to play with window sizing. Between here and other sources I was able to put together a script that sizes a window to what I’d like.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "System Events" to tell process "Bean"
	set position of window 1 to {1, 25}
	set size of window 1 to {1152, 1152}
end tell

Also, I have a simple script that will launch an application.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
	activate
	open application file "Bean.app" of folder "Applications" of startup disk
end tell

But, when I try to put them together like so.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Finder"
	activate
	open application file "Bean.app" of folder "Applications" of startup disk
end tell

tell application "System Events" to tell process "Bean"
	set position of window 1 to {1, 25}
	set size of window 1 to {1152, 1152}
end tell

I get an error “System Events got an error: Can’t set process “Bean” to {1, 25}.”

Any ideas on why they will work separately but not when combined?

First off, what is “Bean” app.

Second you can run an app by doing this…

tell application "Bean" to activate
-- no need to tell Finder

second, when you first launch the Bean app, does it have an open window?

Bean is a very basic MacOS word processor, been using it for many years.And yes, when it launches a new blank window opens.

I’ll try it with your script and the window sizing script combined and see what happens. Thanks.

I’m sure you already knew, but the below works perfectly, thanks!

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

tell application "Bean" to activate

tell application "System Events" to tell process "Bean"
	set position of window 1 to {1, 25}
	set size of window 1 to {1152, 1152}
end tell