Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9195929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:44:16+00:00 2026-06-17T21:44:16+00:00

I am trying to write an applescript script that resizes all open windows. In

  • 0

I am trying to write an applescript script that resizes all open windows. In order to make sure that I’m getting to all the windows, I’m making my script say the name of the application as well as the number of open windows of that application.
Interestingly, while I hear the names of all my open applications, my script says that they all have 0 windows open. How can I fix this issue?

Here’s my code:

tell application "System Events"
    repeat with theProcess in (every process)
        if background only of theProcess is false then
            if name of theProcess is not "Finder" then
                if name of theProcess is "Google Chrome" then
                    say "Chrome woo hoo"
                    say (count windows as string)
                else
                    say name of theProcess as string
                    say (count windows as string)
                    tell theProcess
                        repeat with theWindow in windows
                            say "found a window of"
                            say (name of theProcess) as string
                            tell theWindow
                                click button 2
                            end tell
                        end repeat
                    end tell
                end if
            end if
        end if
    end repeat
end tell

I’m on Mac OS X 10.7.5, using automator 2.2.4 to write/run this applescript

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:44:17+00:00Added an answer on June 17, 2026 at 9:44 pm

    You have to tell the process to count windows. After all it’s the process that knows about its windows, not system events.

    You have told the process to say its name e.g. “say name of theProcess as string” however you only use “say (count windows as string)”… no process is tied to that. Try “count windows of theProcess”. Basically you have lines where sometimes you tell the process, other times you don’t, and other times where you tell the process even though you’ve already told the process, so you do it twice. That’s where you have “say (name of theProcess) as string” but that code is inside a “tell theProcess” block so it’s already being told to theProcess.

    Really you need to go through your code and be more precise. A tip… if you want to click a button in a window then the window must be frontmost on the screen otherwise you can’t click it. Another tip… “name” is already a string so you don’t need to coerce that to a string.

    By the way, I agree with Michael Dautermann’s comment to your post… there will be processes where you won’t get access. But you’ll find that out as you progress.

    Here’s how I would write your code. Basically I would get all of the variables at the beginning using a “tell theProcess” block. Then I can do stuff with those variables. I hope that helps. Notice that I only made the process frontmost which means if it has multiple windows open it will only click a button on the front window. You’ll have to add code to make each window come to the front before you can click its button. Good luck.

    tell application "System Events"
        repeat with theProcess in processes
            if not background only of theProcess then
                tell theProcess
                    set processName to name
                    set theWindows to windows
                end tell
                set windowsCount to count of theWindows
    
                if processName is "Google Chrome" then
                    say "Chrome woo hoo"
                    say windowsCount as text
                else if processName is not "Finder" then
                    say processName
                    say windowsCount as text
                    if windowsCount is greater than 0 then
                        repeat with theWindow in theWindows
                            say "found a window of " & processName
                            tell theProcess
                                set frontmost to true
                                tell theWindow
                                    click button 2
                                end tell
                            end tell
                        end repeat
                    end if
                end if
            end if
        end repeat
    end tell
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying write a script in awk that (among other things) replaces all instances
I'm trying to figure out how to write an Applescript that will Exposé all
I'm trying to write a quick script that will close all but the current
I'm trying to make a script that write text in a file and then
I'm trying to write an Applescript that will make an outgoing Skype call at
I'm trying to write an AppleScript to query iCal and find all the events
Trying to write app for service technicians that will display open service calls within
I am trying to write an apple script that sequentially names my TV shows
The following is part of a larger Script-fu script that I am trying write.
I'm trying to write a script that logs the current app, switches to another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.