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

  • SEARCH
  • Home
  • 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 8122709
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:55:04+00:00 2026-06-06T05:55:04+00:00

I’m writing a script that will constantly scan iTunes for new dialog boxes and

  • 0

I’m writing a script that will constantly scan iTunes for new dialog boxes and close them correctly depending on what they do. For the most part my script is working correctly with the exception that it doesn’t search the buttons of the dialog box.

So far the script will wait until another process opens iTunes, and then wait for the first dialog box to appear (using spin-wait loops). Once a dialog box appears it gets the window and then the window’s buttons. I would like it to then make decisions based on what the buttons are, but I’m having a bad time with finding out what the buttons are. Below is the entire script:

#repeat
set windowOpen to false
tell application "System Events"
    repeat until windowOpen
        if window 1 of process "iTunes" exists then
            set windowOpen to true
        end if
    end repeat
    set windowOpen to false
    tell process "iTunes"
        set frontmost to true
        set wantedWindow to null
        repeat until windowOpen
            try
                set wantedWindow to first UI element whose role description is "dialog"
                set windowOpen to true
            on error erMessg
                set windowOpen to false
            end try
        end repeat
        set buttonList to every button in wantedWindow
        if (count of buttonList) is 1 then
            if title of item 1 of buttonList is not "Stop" then
                click item 1 of buttonList
            end if
        else
            if my windowContainsButton(buttonList, "Cancel") then
                say "Cancel"
            end if
            #           repeat with theButton in buttonList
            #               if title of theButton is "Cancel" or title of theButton is "Restore" then
            #                   say "cancel"
            #                   delay 1
            #               end if
            #           end repeat
        end if
    end tell
    set wantedWindow to null
end tell
#end repeat
on windowContainsButton(listOfButtons, searchFor)
    repeat with theButton in listOfButtons
        if title of theButton is searchFor then
            return true
        end if
    end repeat
    return false
end windowContainsButton

So far, I’m trying to find out if it has found a cancel button by having it say “Cancel”. Instead, it’s coming up with an error: System Events got an error: Can't make |title| of button "Cancel" of window 1 of application process "iTunes" into type reference. It then points me to my function windowContainsButton on this line:

if title of theButton is searchFor then

and it highlights searchFor.

The windowContainsButton function is exactly the commented out section of code, just generalized. The commented out section works, which is a large part of the reason I’m asking about types.

First off, how can I go about implementing a function like this? Lets say that I actually wanted this function to work, how could I make it?

Secondly, is there a better way to do this? I don’t mean the entire script (although I wouldn’t doubt that it could be done better), I mean searching the buttons for a particular button that I’m expecting.

edit: another thing I noticed is that “title” is a reserved word in the body of the script, but a variable in the function. I’m used to other languages where reserved words are reserved universally, so I would also like some guidance with what’s going on there.

  • 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-06T05:55:06+00:00Added an answer on June 6, 2026 at 5:55 am

    I have not gone through the whole script but this should fix your handler:

    on windowContainsButton(listOfButtons, searchFor)
        repeat with theButton in listOfButtons
            tell application "System Events"
                if title of theButton is searchFor then return true
            end tell
        end repeat
        return false
    end windowContainsButton
    

    This is a bit cleaner:

        property theSeconds : 1
    
    tell application "System Events"
        repeat until window 1 of process "iTunes" exists
            delay theSeconds
        end repeat
        tell process "iTunes"
            set frontmost to true
            repeat until exists (first UI element whose role description is "dialog")
                delay theSeconds
            end repeat
            set wantedWindow to first UI element whose role description is "dialog"
            tell wantedWindow
                set buttonList to title of every button in wantedWindow
                if (count of buttons) is 1 and title of button 1 is not "Stop" then
                    click button 1
                else if buttonList contains "Cancel" then
                    say "Cancel"
                end if
            end tell
        end tell
    end tell
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am doing a simple coin flipping experiment for class that involves flipping a

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.